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.