One of our clients has a requirement to migrate attachments to Salesforce Files.

enter image description here They have also enabled this option from Winter '16 to allow file uploads to goto salesforce files instead of attachments.

enter image description here

How can I migrate from attachments to more sophisticated sharing and content versioning salesforce files feature?

  • I believe you do this by creating ContentVersion - that is a child of ContentDocument. See nifty utility (Windows only) FileExporter that can be of assistance appexchange.salesforce.com/…
    – cropredy
    Commented May 19, 2016 at 4:46
  • @cropredy: What you suggests mean that I should have ContentDocument record already present, so it will allow me to have its versions. The problem I have at hand is I can't insert records into ContentDocument. Do I make sense?
    – Mahmood
    Commented May 19, 2016 at 7:01
  • 2
    Inserting a contentversion automatically creates the contentDocument.
    – cropredy
    Commented May 19, 2016 at 14:52
  • Ok. I shall give it a try and let you know.
    – Mahmood
    Commented May 19, 2016 at 15:03
  • @cropredy: I tried loading data via ContentVersion, and it does create ContentDocument. But the problem is still stands. for example, lets say, abc.txt was attached to ABC contact. To relate this attachment to contact after "File" migration would be to use ContentDocumentLink. Which means that I have to first load data into ContentVersion, then export ContentDocument, use Vlookup to update the "LINKEDENTITYID" field in CSV and then upload this new csv into ContentLinkDocument. Please let me know if i have jot-down the steps correctly or is there a better way of migration.
    – Mahmood
    Commented May 20, 2016 at 12:52

2 Answers 2


FYI Douglas Ayers has a package for automating this via Apex: https://douglascayers.com/2015/10/10/salesforce-convert-attachments-to-chatter-files/

  • Nice! My solution gives an in-depth knowledge for the techies to know how salesforce files and enhanced notes work but this solution is very nifty and for those who don't want to get into the nitty gritty of this migration.
    – Mahmood
    Commented Dec 13, 2016 at 14:42

Migration - from Attachment to Salesforce Files

After a lot of RnD, came up with the following:

  1. Export Attachments data using data loader.
  2. Export Attachment files, using data export wizard or File exporter.
  3. Create two fields, ParentId and AttachmentId on ContentVersion object
    • ParentId will hold the id of the entity, attachment was linked to.
    • AttachmentID (with unique constraint) will hold the id of the attachment from attachment object.
  4. Create a CSV, ContentVersion_upload.csv, for ContentVersion with the following fields
    • Attachment_id (AttachmentId from file exported in step-1)
    • PARENTID (Entity Id of the object, from file exported in step 1)
    • Versiondata (local file path)
    • PathOnClient (local file path)
    • Title (title of the file)
  5. Upload (Insert) ContentVersion.csv.
  6. Export ContentVersion data uploaded in step-5.
  7. Create another CSV for ContentDocumentLink (and update ContentDocumentID and ParentEntityId, from the ContentVersion file exported in step-5) with the following fields:
    • CONTENTDOCUMENTID (ContentDocumentId from file exported in step-6)
    • LINKEDENTITYID (ParentId from file exported in step-6)
  8. Upload (Insert) ContentDocumentLink.

I, also, migrated legacy notes to Enhanced Notes . For a complete tutorial on migration of both Notes & Attachments to Files and Enhanced notes please refer to this blog that I created.

  • This is great @mahmood but when you upload the notes and attachments to new Files you lose the history of when they were created an who by. We are looking for a solution that allows us to migrate relevant historical data in notes/attachments into the new Files. We have turned on the create Attachments as Files so any new additions we do not have to be concerned about.
    – iamjury
    Commented Feb 16, 2017 at 22:29
  • To manage historical data from other org or objects, you need to create CustomObject and hold the history for your relevant object. And then display it as a related list or may be create a report for your users to view. A more detailed analysis on the same topic can be found here.
    – Mahmood
    Commented Feb 17, 2017 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .