All Collections
Gearset for data sandbox seeding
How to deploy ContentDocument / ContentVersion Files
How to deploy ContentDocument / ContentVersion Files

Use Sandbox Seeding add-on (Data deployment tool) to deploy ContentDocument and ContentVersion Files with Gearset

Alex Walter avatar
Written by Alex Walter
Updated over a week ago

Note: This article relates to the deployment of ContentDocument / ContentVersion files (Salesforce Lightning files).

Guides to deploying other binary data types are in the following places:

Content files are the Salesforce Lightning way of storing files attached to records. They are stored in the following way: The underlying data for the file is stored in a ContentVersion record, further information on who created the file etc. are stored in the ContentDocument record. This is linked to the underlying record (such as an Account, Contact, etc.) via a ContentDocumentLink junction object record.

You can add them to Salesforce in the following ways:

  • In Lightning Experience, drag files directly onto the Files related list or click Upload Files. To add Salesforce Files, click Add Files in the related list’s menu.

  • In Salesforce Classic, click Upload File in the Files related list.

Files uploaded to the Files related list always become Salesforce Files, whether you’re in Lightning Experience or Salesforce Classic.

Gearset now supports the deployment of this binary data, with some limitations:

  1. It's possible to configure the deployment for one object at the time (for example all files attached to Account)

  2. The deployment tool only deploys the latest version of the file

Example

Below is an example of how to deploy some Accounts and their related ContentDocument Files. This could similarly be applied to deploying Opportunities/Leads/Contacts/etc. (or any custom object) with attached files.

First, include the object type, such as Account you want to deploy the Files with. If necessary, add filters to this object to deploy only the records that are needed.

To deploy the Files for this Account: on the first page of the data deployment, add the type of attachment you want to deploy, in this case ContentDocumentLink (a similar process can be followed for legacy Attachment files).

Enable the 'Filter using parent object' filter to tell Gearset to deploy the files associated with the other records that are included in the deployment.

There are a few things to check on the second page (related objects):

  • Binary objects can only be deployed by a 'create' step, so ContentDocumentLink (or Attachment) must be set to 'Create new records'.

  • When deploying Files, ContentDocumentLink will appear on the left-hand side of the page and ContentDocument and ContentVersion will appear as related objects on the right-hand side.

  • All three objects must be selected for deployment for the attachments to be successfully created on Salesforce.

  • ContentDocument is not deployed by Gearset, but instead created by Salesforce on the target organization, so it uses the special deployment type 'Read back created records', which looks up which records were created.

This is all that's needed to configure the deployment. It's possible to check that the attachments will be deployed by looking at the deployment plan. The fetch step will be filtered by the 'parent' object, and the file itself will be deployed using a 'create binary' step.

Troubleshooting

If you're not the owner of the attachments you are trying to deploy, then you may encounter an error message like the following:

Documents in a user's private library must always be owned by that user

The solution to this is to exclude the User object from the deployment on the related objects page. This will ensure that the attachments are created with your deployment user (and not the original owner) set as the owner, meaning that we won't attempt to store the attachments in the original user's private library.

Did this answer your question?