Pages

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.




Reference:


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.


Reference:


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