Working with files in Salesforce can sometimes be a little tricky. There are a couple of different ways Salesforce can add files to a record: they can either be Attachment records (legacy format from pre-Lightning days) or they can be added as ContentDocument records (modern format). These have a few different layers and are linked up in the following way:

The files will be typically be shown under the Notes & Attachments section for a record such as an Account or a Contact:

For the ContentDocument type Files, 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.

If a record with an attached file has been deleted, the easiest way to restore this is via the Restore <Object> with dependencies. We will walk through an example of a deleted Account record (which has files attached to it).

Initially we notice that the Account record has been picked up as been deleted when we view the run:

Once we click on Restore or Restore Account with Dependencies

Gearset will show you a dependency tree of records that have been deleted (for more information on this page in particular, see this documentation).

Select the Files (ContentDocument) - this will include all the related records for restoration in a single-click: the associated ContentDocument, ContentVersion, ContentDocumentLink records. Click Preview Restore to build up a restoration plan:

Then Deploy Data to restore the data to your Salesforce org. Once this completes, it will show a summary like this

The Account record along with the attached file are now restored to Salesforce:

If you are looking to deploy attached files to another org, please see this documentation.

Please reach out to us in the chat widget if you would like any further help with this.

Did this answer your question?