Working with Existing Attachments in Visual Workflow

You can manipulate attachments in visual workflow (i’m working with the old-fashioned attachments object, but this should work w/ files, which are stored as contentDocument / contentVersion / contentDocumentLink).

What works: manipulating existing attachments by looking up the attachment(s) and storing them in a sObject variable/collection, including the body field. Use assignment elements to set the ParentID to its new parent, and use a fast create to insert the sObject variable/collection.

What wont work: Doing anything with the body field, other than including it in a sObject variable/collection. For example, I tried to map a text variable to body and create a new text attachment, and that fails. Body is a base64 field type, and I have not found any flow field type that can map to it. So you can only lookup an existing attachment and change the parent ID - you cant create new ones.

Use case: create a button that copies attachments from a case email to the case itself.

Screenshot 2016-10-06 at 9.57.03 AM.png

Design Summary:

  1. Fast Lookup: getEmail: query email to get parent case ID
  2. Fast Lookup: getAttachments: query attachments and store it in a Sobject Collection, including the body field
  3. Loop: loop through attachments
  4. Assignment : set the parent ID to the case
  5. Assignment : add loop variable to a new sObject collection for insert
  6. Fast Create: createAttachment: insert the new attachments


Additional Flow Elements:
variable: vaEmailId (id of email that has attachments)
variable: vaCaseID (id of parent case on email)
custom button: on email object: launches flow and passes in the email ID

A few key details

  1. make sure you include the body field in the fast lookup (step 2). really just include all the standard fields on attachment b/c why not.
  2. both assignment elements have one item each. asst set parent id just sets the parentId on the loop variable. asst add attachment to new collection just adds the loop variable to a new sObject collection

Note: This approach does appear to conflict with the documentation on the fast create resource, which states:

The object types must match, and each ID field must not have a value.

In this case, the ID field in the NewAttachment sObject collection most definitely has values. You can see this by adding a screen element to display the sObject collection prior to the fast update (which is a great flow debugging trick - sObject collections in screen elements will display their IDs, if an ID exists).


For a more advanced version, you can use a dynamic choice field to select which attachments to include, if there is more than 1 attachment. It requires a trick - but it works. Additional post coming soon someday!


Now read this

Including Case Comments in Case Assignment Email

Including case comments in the case assignment email allows the recipient to see exactly what is going on before even logging in to Salesforce. You need a visualforce email template for this. You can use an apex:repeat component in your... Continue →