anusha(salesforce developer)

Friday 24 June 2016

Can we set Salesforce user password?

As Salesforce administrator, we often get question from our user, "can you check what is my password? " hmmmm, some users often think like some legacy applications, where system admin able to see or modify Salesforce password.

In Salesforce is different, it is so secure, system admin and everyone else not able to see or modify any user password. But, as the best practice, we offer to reset their password, and Salesforce will send email to the user with instruction to set new password by  their own, and it should works fine.


But again, some users (read: senior management) not really want to bother by checking email and so on, even the request is come from his/her secretary. So how? No problem, we can change user email to her secretary email, secretary confirm email change in her email (although Salesforce also will email to the original email say that the email has been changed to new one), and reset password. It works, yay!!! 


But, how to change back the user email to the original one? The senior management need to click a link again in her email (she may have hundreds or thousands email never read). Problem.


So, I just start think if there is an easy way to set user password without have to go through such complicated process? It is worst when the user is going to present something in 5 minutes and we do not have much time to do above process. So, can we set user password?


YES, it is possible, this function is not exist in Salesforce setup menu, but Salesforce is kind enough to provide system administrator with Developer Console. Yes, Developer Console is for developer as it named, but admin also can use it for other purpose, like set user password, yay!!!



How? It is easy, just few clicks, copy and paste a short code below will do. Navigate to your name and click Developer Console menu.  It will open new window, Debug | Open Execute Anonymous Window, copy and paste code below to the Enter Apex Code windows and click Execute button. System.setPassword('00550000000rlrX', 'hello123');



In this sample: 00550000000rlrX is the User Id, if you are Salesforce admin, you should now this Id well, and hello123 is the new password to set.


But, if you still too lazy to check the User Id manually, and you have the username, you can just copy and paste statement below into Apex code execute box:
System.setPassword([SELECT Id FROM User WHERE username='joe@lazy.com'].Id, 'hello123');

Below sample code to set password of all active user in one go:

List<User> userList = new List<User>();
userList = [SELECT Id from User WHERE IsActive = true];
for (User u : userList)
{
    System.setPassword(u.Id, 'hello123');
    System.debug('DONE: ' + u.Id);
}

You can modify the SOQL above as needed, example: only for profile = "Sales Rep".


All statements above is apex code, but we can utilize it for other productive work as needed. 

Show value only to Owner and Manager?

Use case:
A scoring system has been implemented to auto calculate if a lead is valid to pursue. But, the score should only visible to the record owner manager.

In Salesforce, we only can set field visibility using Field Level Security (FLS) which is based on Profile. But record owner manager have the same profile with the record owner, and the manager may owned a lead which he supposed not able to see the score, only the manager's manager able to see it.

Solution:
1. Set the score field not visible from all Profile with FLS
2. Create a formula field and make it visible to all Profile
IF( $User.Id = Owner.ManagerId, Score__c, null)

For other scenario, if only the owner and owner's manager should be able to see the score, use this formula:
IF( $User.Id = OwnerId || $User.Id = Owner.ManagerId, Score__c, null)

How to export Attachments ?

In previous blog, we discuss on how to mass upload files to Salesforce as attachment? But, can we export attachment using Data Loader? Yes, but the files exported will be in binary format in a CSV file, it is not in the original filename and format, so how?

One of the solution using File Exporter, it is a free app develop by Salesforce Lab. But, this application actually is pretty complicated, it only work with some version of Data Loader only. I cannot make it works, although has follow the steps in document.

Finally, we find a free and easy tool to export files back to the original format. It is http://dataloader.io, a product of Mulesoft, the free version already support our need. With paid version, you can: schedule more task, SFTP support, number of connections, task expiration and support.

How it works?
1. Login to http://dataloader.io with your login to Salesforce, it use SSO
2. Click "New Task" and select "Export" button
3. Select Attachment object, click Next
4. You can select just the Body field, or with some fields, or all fields
5. Click "Save & Run"
6. Wait the process


Once the task done, you can download the attachments by clicking on the task manager on the link next to the export task. This will download all of the attachments compressed into a .zip file, example: Attachment Export-02_13_2014-13_43_08.zip

If you select other fields on top of Body field, you will find a CSV file with the same name, example: Attachment Export-02_13_2014-13_43_08.csv, all fields selected when you in  export in dataloader.io will be available in this CSV file.


Note: Dataloader.io is not Salesforce product, so your data actually will stay or pass through someone else database, please seek your IT policy.

Salesforce SOQL query LAST_WEEK ; LAST_N_DAYS:n ; N_DAYS_AGO:n

Salesforce SOQL query LAST_WEEK ; LAST_N_DAYS:n ; N_DAYS_AGO:n


LAST_WEEK
Using criteria LAST_WEEK in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) on the first day of the week before the most recent first day of the week and continues for seven full days. First day of the week is determined by your locale.
Example: my user locale setting is English (United States) and today = Sat, 23 Nov 2013, I run query below:
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = LAST_WEEK ORDER BY CreatedDate DESC
this query will return accounts created between 10-16 Nov 2013, because for Locale is US English, a week runs Sunday to Saturday, whereas with UK English, a week spans Monday to Sunday.

SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate < LAST_WEEK ORDER BY CreatedDate DESC
this query will return accounts created before 10 Nov 2013.

LAST_N_DAYS:7
Using LAST_N_DAYS:7 in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) of the current day and continues for the last 7 days.
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = LAST_N_DAYS:7 ORDER BY CreatedDate DESC
If today is Friday, 22 Nov 2013, using LAST_N_DAYS:7 will return account created between 16 - 22 Nov 2013, while LAST_WEEK will return account created between 10 - 16 Nov 2013.

N_DAYS_AGO:7
Using N_DAYS_AGO:7 in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) on the day 7 days before the current day and continues for 24 hours. (The range does not include today.)
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = N_DAYS_AGO:7 ORDER BY CreatedDate DESC
If today is Monday, 25 Nov 2013, using N_DAYS_AGO:7 will return account only created on 18 Nov 2013. 

Please note all Date field return in SOQL query will be in GMT format, example: 2013-11-18T08:05:21.000Z, so you need to convert it as needed

Notes and Attachments in SFDC

Notes and Attachments is not a new thing in Salesforce. I also do not see any enhancements in last few Salesforce release. But, for some users, Notes and Attachments still a nice feature and frequently used.

Here a few facts on Notes and Attachments good to remember:
  1. It is not possible to report on the Notes and Attachments related list.
  2. The Notes & Attachments can be exported directly via the API.
  3. It is possible to access your Notes & Attachments data by requesting a full data export of your organization's data. 
  4. The only way to get attachment on an Salesforce email to Attachment is to download the attachment to your local machine, then manually added as an Attachment from the local machine location.
  5. Notes and attachments marked as Private via the Private checkbox are accessible only to the person who attached them, Administrators and users with View All Data permission.
  6. You must have “Read/Write” access to parent record to be able to add Notes or Attachments to the record.
  7. You also need to have “Read/Write” access permission to parent record to be able to edit or delete Notes or Attachments.
  8. You can write Apex trigger for Notes & Attachments using Force.IDE
Special thanks to Jason Lawrence for the input of Feed Attachment, so if you attach File to Chatter Feed in an Account or Opportunity, it will show as well in Notes & Attachments as Feed Attachment.

Custom Button to pre-populate Fields

Out-of-the-box, when we create a new record from a parent object related list, Salesforce.com provide parent name pre-populated in child object. This is efficient and save time, user do not need to look for the parent record again.





This is good, but, often we need more fields to be pre-populated for some scenario and make our (read: Salesforce users) life easier :)
We can make this happen by create new custom button whether in related list or in page layout. In this sample, we'll use Account as parent and Opportunity as child.

NOTE: This is considered a URL hack and it is not supported by Salesforce. Using undocumented query strings is absolutely discouraged as Salesforce can change them at any time without notice.

Custom button in page layout
Go to Account object in Setup menu and choose Buttons and Links. Click New button and select option as screenshot below. Once button created, you need to add the button into Account page layout.


Custom button in related list
Go to Opportunity object in Setup menu and choose Buttons and Links. Click New button and select option as screenshot below. Once button created, you also need to add the button in Opportunity related list in Account page layout.





OK, now we understand how to create the custom button, but what is the URL??? Here we go...

If you click Opportunity button in related list, see the URL
https://na1.salesforce.com/006/e?retURL=%2F0019000000DjwR5&accid=0019000000DjwR5&RecordType=01290000000NLfk&ent=Opportunity

So, what is the parameters and values? Let's parse it:
https://{instance}.salesforce.com/{object_prefix}/e?retURL=/{!Object.Id}&accid={!Object.Id}&RecordType={RecordTypeId}&ent={object_name}

In this sample there is record type in Opportunity and we want to skip Record Type selection page when user click new Opportunity by populating Record Type Id in the URL. So, this would be the URL:
/006/e?retURL=/{!Account.Id}&accid={!Account.Id}&RecordType=01290000000NLfk&ent=Opportunity


Now, we want to pre-populate other field from Account. Here we go... you need to find out the Id of textbox from web browser, in page edit the record and right click at textbox then select Inspect element

Once you get the id, add it into the URL:
/006/e?retURL=/{!Account.Id}&accid={!Account.Id}&RecordType=01290000000NLfk&00N90000000iQg4={!Account.Hello__c}&ent=Opportunity


Custom object
Parameter for pre-populate for lookup to an custom object id different, see sample below:
https://na1.salesforce.com/a0E/e?CF00N900000022p5z=Object+2A1&CF00N900000022p5z_lkid=a0D90000001OPvT&saveURL=%2Fa0D90000001OPvT&retURL=%2Fa0D90000001OPvT

Let's parse it:
https://na1.salesforce.com/{object_prefix}/e?CF00N900000022p5z={parent_object_name}&CF00N900000022p5z_lkid={parent_object_id}&saveURL=/{parent_object_id}&retURL=/{parent_object_id}

Notice that parent name is CF00N900000022p5z and parent id is CF00N900000022p5z_lkid and a new parameter saveURL to redirect the page after user hit Save button.


Considerations
Before you add more and more fields pre-populated, please consider this:
  • Sometime, if field in child object is not edit-able, consider to use formula field in child object
  • If the field do not need to copy from parent, you can hardcode it into the URL
  • To pre-populate data with some logic, you need visualforce page with apex code.


Auto-save
Some of you may looking for a way to autosave the record, Salesforce used to support parameter save=1, but for security reason to prevent Cross-Site Request Forgery (CSRF), this parameter has been removed.
You may look for AJAX toolkit to update + save record from a button.

Salesforce Change Set


List of Component Type available in Change Set:
  • Action
  • Action Link Group Template
  • Apex Class
  • Apex Sharing Reason
  • Apex Trigger
  • App
  • Approval Process
  • Assignment Rule
  • Auth. Provider
  • Auto-Response Rule
  • Button or Link
  • CORS Whitelist Origin
  • Call Center
  • Communication Channel Layout
  • Compact Layout
  • Custom Console Component
  • Custom Field
  • Custom Label
  • Custom Metadata Type
  • Custom Object
  • Custom Permission
  • Custom Report Type
  • Custom Setting
  • Dashboard
  • Dataflow
  • Document
  • Email Template
  • Escalation Rule
  • External Data Source
  • Feed Filter
  • Field Set
  • Flow Definition
  • Folder
  • Global Picklist
  • Group
  • Home Page Component
  • Home Page Layout
  • Language Translation
  • Letterhead
  • Lightning Component Bundle
  • Lightning Page
  • List View
  • Matching Rule
  • Name Credential
  • Opportunity Split Type
  • Page Layout
  • Permission Set
  • Platform Cache Partition
  • Post Templates
  • Queue
  • Record Type
  • Remote Site
  • Report
  • Reporting Snapshot
  • Role
  • S-Control
  • Send Action
  • Sharing Criteria Rule
  • Sharing Owner Rule
  • Sharing Territory Rule
  • Site.com
  • Static Resource
  • Tab
  • User Provisioning Config
  • Validation Rule
  • Visualforce Component
  • Visualforce Page
  • Workflow Email Alert
  • Workflow Field Update
  • Workflow Outbound Message
  • Workflow Rule
  • Workflow Task
  • Zone
The one in purple is just to mark new components added since Summer'15 release.

Note:

Search Layouts is not available as independent Component in Change Set, but when you deploy the object, all Search Layouts for that object is included.

For Custom Settings, you need to re-create or export/import (e.g. using Data Loader) the data set/values in the target org, Change Set will only deploy the Custom Setting shell.

Custom Fields from Custom Settings will be treat as per normal Custom Fields from object.

The components available for a change set vary by edition. Some components require corresponding features to be enabled in your organization, such as: Sharing Territory Rule will not available if Territory  is not enabled. 

If you create or modify components that are not available in a change set, you can't send those components from one organization to another in a change set. In this case, migrate the changes manually by repeating the steps you performed when you created or modified the component.

List Views are visible to all users when you deploy a change set. Change the visibility in the destination organization as necessary. See more information related to List View for change set here List View not visible in Change Set.
Deployed custom tabs are hidden by default for all users. They’re visible only if the change set also contains profiles that set the visibility property appropriately. Professional Edition organizations are an exception—deployed custom tabs in those organizations are always visible by default.

ISBLANK() or ISNULL() in sfdc

To determine if an expression has a value or not, you can use ISBLANK()function in Salesforce. It will  returns TRUE if it does not and if it contains a value, this function returns FALSE. You can use this function in formula field, validation rule, and workflow.

Syntax: ISBLANK(expression) -- replace expression with the expression you want evaluated, sample: IF(ISBLANK(Main_Amount__c), 0, 1)

A field is not considered as empty if it contains a character, blank space, or zero. For example, a field that contains a space inserted with the spacebar is not empty.

When using this function with a numeric field (currency, number, and percent field type) for a formula field, choose Treat blank fields as blanks in the Blank Field Handling section. Otherwise, if you choose Treat blank fields as zeroes, it will gives the blank field value with zero, so none of them will be null. While it will work in validation rule and workflowwithout exception as in Formula field.


ISBLANK() work with following fields type: Text, Email, Text Area, Picklist (Multi-Select)NumberCurrency, and Percent.
But, it does not work directly with fields type: Picklist, Long Text Area, and Rich Text Area.

For Picklist field, we can use TEXT() function before ISBLANK(), example: ISBLANK( TEXT(Ini_Picklist__c) )or ISPICKVAL(Ini_Picklist__c, "").

For Long Text Area and Rich Text Area field, instead of using ISBLANK(), use LEN() function, example: LEN(Ini_Long_Text_Area__c) = 0, but not for formula field.

** Long Text Area and Rich Text Area field is not supported in Formula field.


You also can use BLANKVALUE() function to determine if an expression has a value and returns a substitute expression if it does not. If the expression has a value, returns the value of the expression.
sample:
BLANKVALUE(Payment_Due_Date__c, StartDate +5)
Use the same data type for both the expression and substitute_expression.

How about ISNULL() ?
Use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same functionality as ISNULL, but also supports text fields. Salesforce will continue to support ISNULL, so you do not need to change any existing formulas.

The same goes for NULLVALUE(), it is similar with BLANKVALUE(), with exception:
  • Avoid using NULLVALUE with text fields because they are never null even when they are blank. Instead, use the BLANKVALUE function to determine if a text field is blank.
  • Don’t use NULLVALUE for date/time fields.

How to log Case to Salesforce support

Two months ago (around late Oct 2015 - after Winter '16 release), Salesforce change Help and Training portal to a whole new experience. There are 4 main areas improvement in the new portal:
1. Mobile friendly: open web browser from Tablet and smart Phone.
2. My Success Hub: Dashboard, Open and Closed Cases, Training, and Contact Us.
3. Help Finder: Step by Step guided experience with answers at every corner, this is good for user to have self-service.
4. Auto complete Search: based on multiple sources, portal will auto complete and recommend question you may ask.

But, somehow for experience admins or consultants who familiar with the system, to log a case become another challenge. In earlier new version, it buried somewhere under "click here" link - explained by this article Submit, create or update a case with Salesforce Support. This week (before Christmas 2015), we see a newer version released again (2 months after initial portal released), so above article become no longer valid.

So, as of today 26 Dec 2015, here is the step by step on how to log Case to Salesforce support. After click Help & Training link at top right in Salesforce.com

1. Click Contact Support



2. Select a Topic



3. Select a Category


4. Log a Case 
You will see Log a New Case big icon, if you do not see that icon here, it may depend on your level support or Category you choose, you may not see the icon here, continue to step 5 below.



5. Select a Question 
If you do not see the icon at step 4, click a Question (in gray cell), this will bring you to Solution tab. Look for the icon below.



If you not so happy with the new portal, feel free to vote for this idea to have easier way to log a Case, maybe from My Success Hub.


Reference:

Convert Multi-Select Picklist to Text in SFDC

Convert Multi-Select Picklist to Text


Multi-Select Picklist is nice for user to use in Salesforce user interface, but there are many limitations for admin to use this type of field, because it support limited functions compare to other fields type.

More than a year ago, we blog about How to sort Multi-Select Picklist in View? This blog will share about how to convert Multi-Select Picklist to Text, so you can use it in many areas.

As of now (Summer '16 release), multi-select picklist only support following functions:
  • INCLUDES()
  • ISBLANK()
  • ISNULL()
  • ISCHANGED() - only in assignment rules, validation rules, workflow field updates, and workflow rules in which the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited.
  • PRIORVALUE() - only in assignment rules, validation rules, workflow field updates, and workflow rules in which the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited.

With a simple formula field return text format, you can get the multi-select picklist values in Text.
Let say you have a custom multi-select picklist field called Country__c with 5 values. Here is the formula:
 IF( INCLUDES(Country__, 'Singapore'), 'Singapore,', null) +   
 IF( INCLUDES(Country__, 'Indonesia'), 'Indonesia,', null) +   
 IF( INCLUDES(Country__, 'Malaysia'), 'Malaysia,', null) +   
 IF( INCLUDES(Country__, 'China'), 'China,', null) +   
 IF( INCLUDES(Country__, 'Japan'), 'Japan,', null)