Please enter your search criteria to begin searching

Migrating Files between Salesforce Orgs

Migrating data is a bit like marmite, you either love it or hate it. You need to have an understanding of how data is organised by tables, rows and columns in a relational database, plus have a very methodical and tenacious nature which you don’t mind being put to the test. So, if you’ve already switched off from this blog, data migration may not be your thing.

For anyone still reading who may have been tasked with migrating Files from one Salesforce org to another, this is for you. I have performed a fair amount of data migration in the past, but nothing could have prepared me for migrating Files as that’s a whole different ball game. I found various papers explaining how to do parts of the migration, but nothing that explained the end-to-end process, so my aim here is to do exactly that and save you from the trials and tribulations I experienced.

There are 3 main stages for org-to-org File migration:     

  • Exporting Files from the source org (Steps 1-2)
  • Importing said Files to the target org (Steps 3-4)
  • Relating the imported Files to existing data (Step 5) - this is where the bulk of the work will be!

Step 1

Use the Data Export function in Salesforce to export the Files. Check the box ‘Include Salesforce Files and Salesforce CRM Content document version’. You don’t need to export the actual data.

This creates one or more zip files. When you extract them, look out for the following:

ContentVersion folder (contains the Files so there may be more than one folder)

ContentVersion.csv (contains the ID of each File)

ContentDocumentLink.csv (contains the IDs to relate Files to records)

Step 2

Unzip the ContentVersion folder(s) into a single ContentVersion folder on your local drive.

Step 3

This is where you prepare to import the Files into the target org. Recreate the ContentVersion.csv file from Step 1 with:


(Required) - File name




(Required) - The path name of where you have stored the Files in Step 2

(e.g. C:\Files\ContentVersionAll)

Version Data

(Required) - The PathOnClient, plus the file Name

(e.g. C:\Files\ContentVersionAll\0680P000006N82BQAS - this is the File Name found in the ContentVersion folder)


I would also recommend creating an External ID field on the target ContentVersion object to hold the original Salesforce ID, as this will assist with relating records correctly further down the process.


Step 4  

Use the new ContentVersion.csv file to insert the Files into the target org ContentVersion object.

Step 5

Now that the Files have been imported to the target org, each File will have been allocated a new ContentDocumentID. This will now be used to link the File to the related records. 

  • From the target org, export the ContentVersion object using the same fields as in Step 3, plus the ContentDocumentID field
  • Open the exported ContentVersion.csv file and the ContentDocumentLink.csv file from Step 1 (I would recommend keeping a copy of the original file in case you need to refer back to it)

Here’s the tricky bit. You now need reconstruct the ContentDocumentLink.csv file, using the IDs from the target org, which could be different to the IDs in the source org (if you have performed a data migration prior to this). This should be made simpler by using the External ID from Step 3 to match the records. Choose whichever method you are comfortable querying data with, e.g. lookups in Excel, MySQL queries or even MS Access. There is no ‘right’ application or method to use.

The new ContentDocumentLink.csv file (which you will then import into your target org), needs to be constructed as follows:


(Required) - From the import success file in Step 4, or the export in Step 5


(Required) - The record ID of the related record in your target org


(Required) - The permission granted to user. For valid values, see the 'Description' details for the field in the ContentDocumentLink | SOAP API Developer Guide


(Optional) - Specifies whether this file is available to all users, internal users, or shared user. Refer to the field's 'Description' details in the guide link above


Good luck!


© Copyright Stimulus Consulting 2015