Using Files and Attachments in Flow

Here’s some information you might find useful when incorporating files and attachments into your Flow.

Documents (like Word, PDF, Excel, images) can be associated with Salesforce records.

Attachments

The old way to do this was as Attachments. An Attachment can be queried with a Get Records, and is linked to a record via the ParentId field.

Files and the Content Family of Entities

However, Salesforce has replaced the Attachment paradigm with a more flexible and modern mechanism that allows for multiple versions of a document to exist. This mechanism involves three different types of entity:

  • Content Document represents the file in the abstract. But “real” versions of this document are distinct and have different version numbers, so there’s also a…
  • Content Version represents a specific version of the Content Document. A Content Document can have multiple Content Versions
  • Content Document Link is used to connect a Content Document to a record.

Sending Attachments in Email

Salesforce provides a powerful email sending service, and the Send HTML Email action allows you to use it in Flows. The Email services used by this action use an entity called an Email File Attachment which is similar to the Attachment object described above. Because of this similarity, the Send HTML Email action has been designed to accept a collection of Attachment objects.

If you have records that include Files stored in the Content Document and Content Version format, you’ll want to use the ConvertFilesToAttachments action to convert them to the Attachment form that the Send HTML Email action is expecting.

In the below flow, we first retrieve all of the documents associated with the passed in recordId. This returns a collection of Content Document Links. We pass those to ConvertFilesToAttachments and it returns a collection Attachments, which we then pass to the Send HTML Email.