Salesforce has two ways to attach files to records. Prior to the introduction of Lightning, there were simple attachments. These are stored in the Attachment object, which has a single ParentId field that specifies which record the attachment is for. With Lightning, Salesforce introduced Files as a replacement for the older attachment system. Instead of a single object, this new style of attachment uses a more complicated set of objects. The ContentVersion object stores the binary data,

ContentDocument is used to group multiple versions of a single file, and the new ContentDocumentLink junction object takes the place of the ParentId field, allowing a single file to be attached to many other records if needed.

Both types of attachment are supported for data deployment and backup restores in Gearset.

First, include the object type you want to deploy attachments for in the deployment. Many different objects support attachments: for the purposes of this example, we've chosen Account. If necessary, add filters to this object to only deploy the records that are needed.

To deploy the attachments for this Account, while still on the first page of the data deployment, add the type of attachment you want to deploy.

  • for attachments added before Lightning, choose the Attachment object, and

  • for attachments added in Lightning, choose ContentDocumentLink.

In both cases, enable the 'Filter using parent object' filter in order to tell Gearset to deploy the attachments associated with the other records that are included in the deployment. For more complicated deployments, it may be necessary to select the object whose attachments should be deployed using the dropdown.

On the second page (related objects), there are a few things to check. Binary objects can only be deployed by a 'create' step, so Attachment or ContentDocumentLink 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 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 can check that the attachments will be deployed by looking at the deployment plan. The fetch step will be filtering by the 'parent' object, and the attachment itself will be deployed using a 'create binary' step.

Restore from a backup

When restoring from a backup it's common to make the mistake of choosing the wrong run to restore from.

Imaging you have run X, where you back up the file, and a subsequent run Y where the file deletion is detected. You will need to go to the run Y to take the ID information of what you want to restore, but then go to run X click on Restore snapshot data to start the configuration.

Did this answer your question?