Wednesday, February 21, 2018

Salesforce: Mass Upload files to Files using Data Loader

Many years ago, I wrote a blog Salesforce: Mass Upload files to Attachment using Data Loader, that blog explains step by step from preparing CSV file and execute from Data Loader to upload file into Salesforce as Attachment.

In the era of Lightning, "attachment" has been replaced by "files", if you are still using the old "Notes & Attachments" related list in Lightning, the file uploaded from Lightning actually is stored as Files, no longer as Attachment.

1. Prepare CSV file
You can use Microsoft Excel to create new CSV file with following columns:
  • Title - this is text that will show as Title of the file. 
  • Description - (optional) description if the file.
  • VersionData - complete file path on your local drive, example: c:\data\test1.docx
  • PathOnClient - complete file path on your local drive, example: c:\data\test1.docx
  • OwnerId - (optional) file owner, if not provided, owner would be to the user uploading the file.
  • FirstPublishLocationId - this can be Account Id for file need to be linked to Account, or Opportunity Id, or User Id, or Library Id (Library Id start with prefix 058).
  • RecordTypeId - if you define record type under "Salesforce Files" setup menu. To check if you have any record type for Files, query this Select Id, Name FROM RecordType WHERE SobjectType = 'ContentVersion'.
  • TagsCsv - (optional) tag.
A sample of CSV file here.

2. Data Loader
With the latest Data Loader application, you can login to Salesforce with OAuth or Password Authentication, make sure to select "Show all Salesforce objects", then look for object "Content Version (ContentVersion)".

Follow the steps, if no error occurred, all the files listed in the CSV file should be loaded to Salesforce as Files. If you are using Lightning but still using Notes & Attachment related list, you will see the file is appeared in Notes & Attachment too, although technically, it is stored as Files, instead of Attachment.


Monday, February 19, 2018

Salesforce: Lightning Experience Adoption Query

So, you are ready to switch to Lightning, but your management decides not to set "Hide Option to Switch to Salesforce Classic" permission. How can you check on how many users have switched to Lightning for good?

Salesforce provides an app you can install from AppExchange Lightning Adoption Tracker, but one of the criteria of this app, that you must enable My Domain.

Once this app installed, you will find a few reports and dashboards added, and a reporting snapshot that needs to be configured, for detail of the steps, see this guide.

Additionally, there are 2 fields added into User object:
“Can Use Lightning”: this custom field stores whether the user has the user permission enabled.
“Using Lightning”: this custom field stores the user preference value.

Can Use Lightning determines how many users have the permission to switch to Lightning, but if you would like to query without installing the package, get it from PermissionSetAssignment object.
SELECT Id, AssigneeId, Assignee.UserName, PermissionSetId, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsLightningExperienceUser = True ORDER BY Assignee.UserName

You need to get unique AssigneeId as this query may report duplicate if the user has more than 1 record permission to enable Lightning. Check this blog Using Permission Set to Query User Permission to learn more about the query on Permission Set.

Using Lightning determines users have switched to Lightning Experience, here is the query from User object without need to install the package
SELECT Id, IsActive, ltnadptn__Can_Use_Lightning__c, ltnadptn__Using_Lightning__c, UserPreferencesLightningExperiencePreferred, Username FROM User ORDER BY Username 

Two fields start with ltnadptn__ are part of Lightning Adoption Tracker packaged installation. Ideally, ltnadptn__Using_Lightning__c and UserPreferencesLightningExperiencePreferred should be the same value, but as ltnadptn__Using_Lightning__c is populated hourly by apex schedule job, so you may see them in sync after an hour.


Thursday, February 8, 2018

Salesforce: Reporting on Relate Contact with Multiple Accounts

More than 1 year ago, we wrote a blog about Relating Contact with Multiple Accounts including the security model to add, edit and remove relationship.

In this blog, we'll share how to report Contacts relate to other Accounts, including if they are direct linkage, active, start date, and custom fields added under  Account Contact Relationships.

1. Create Custom Report Type
- From setup menu: search for Report Types by type in the Quick Find box.
- Click New Custom Report Type button
- Select Primary Object = Contacts, you can enter the Report Type Label, Description, and store it under a Category.
- Click Next button to continue

- In Step 2. Define Report Records Set, click relate to another object.
- Select Account Relationships

- Click Save

2. Create Report
- Type the report type name created in step 1 from Quick Find box
- Click Create button
- Here you will find Direct, Active fields under Account Relationship section at left panel
- Save the report and type a report name
- Run the report

For all contacts where Direct is not ticked, they are added from Relate Account relationship.

Here is the screenshot from one of Sean Lee (one of the contact) that not directly link to Ahui Jack account.

For those of you who more interested in the query using SOQL, here a sample:
SELECT Id, AccountId, ContactId, CreatedById, CreatedDate FROM AccountContactRelation WHERE IsDirect = False

Monday, January 22, 2018

Implementing Custom Permission for Workflow and Process Builder

More than 3 years ago, we wrote a blog on implementing Custom Permission for Validation Rules. In this blog, we are going to share the same Custom Permission, but for automation, including Workflow and Process Builder.

We'll not discuss further on how to create Custom Permission and Permission Set, so please check the blog mentioned earlier if you need a reference to create Custom Permission and Permission Set.

From Workflow Rule Criteria, select formula evaluates to true.
If you have Custom Permission created, you will see $Permission > under Insert Field.

In this sample, I have a Custom Permission name "Edit_Customer_Custom_Permission", select that permission and add it to Rule Criteria $Permission.Edit_Customer_Custom_Permission.

With this criteria, only users assigned to the Permission Set will trigger the workflow, otherwise, the workflow will not be fired.

Process Builder
Let's use the same Custom Permission - Edit_Customer_Custom_Permission. From Criteria - "Define Criteria for this Action Group"
1. Select Formula evaluates to true.
2. In the Build Formula panel, click System Variable.

3. Select Permission >

4. Type or select the Custom Permission, click Choose button.

5. Now you have the formula built $Permission.Edit_Customer_Custom_Permission.

This is the same criteria with Workflow criteria's above.

ReferenceCustom Permission for Validation Rule

Thursday, January 18, 2018

Salesforce: Recycle Bin in Lightning

As of Spring '18 release, Recycle Bin is still not exist Lightning, vote my idea Lightning Experience - Recycle Bin to get this delivered in coming release.

However, if Recycle Bin is a must, and you can't wait if they will be made available in the future release, here is the workaround.

1. Access to page /search/UndeletePage
If your Lightning URL is change this to

Once you access the page, you will see Recycle Bin as in Classic. Note, this is only applicable to users allowed to switch back to Classic. When you finish and click any tab or record, it will bring you back to Lighting.

2. Add to Lightning Component
It would be troublesome to communicate to all users to bookmark that page.
Adding the "Recycle Bin" link to a page will be much easier, including for training and writing manual guide.
With a simple Lightning Page editing, add a Rich Text component, in my case, I add it to the Home page.

Additionally, there is a 3rd app in AppExhange to add Recycle Bin in Lightning

ReferenceLightning Experience - Recycle Bin

Friday, January 12, 2018

Salesforce: Update Records criteria in Process Builder

Until Spring '18 release, in Update Record action, if we have multiple conditions, we can't customize the logic for the condition with AND, OR. Feel free to vote my idea Process Builder - filter logic in Updating Records action.

no option to define logic

While in Define Criteria, the option to customize logic is available since long time back.

If we drill down further, for the condition in Record Update, by default the relation for each condition is AND, however, if we define more than 1 condition using the same field, the relation of the conditions for the same field would be OR, here an example:

From above sample, we define Account Source twice, and Support Level twice, the logic for this can be translated as (1 OR 2) AND (3 OR 4).

Here quote from Salesforce documentation Update Records from a Process.
When you define multiple filters, the filter logic usually defaults to AND. However, if multiple filters have the same field selected and use the equals operator, the filters are combined with OR. For example, your filters check whether a case’s Type equals Problem (1), Type equals Feature Request (2), and Escalated equals true (3). At runtime, those filters are combined to (1 OR 2) AND 3.

ReferenceUpdate Records from a Process