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: use assignment element to set the parent ID to the case
  4. Fast Create: createAttachment: insert the new attachments

allattachments_summary.png

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

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).

socNewAttachments.png

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!

 
5
Kudos
 
5
Kudos

Now read this

Infinite Flow Refined

UPDATE - 7.7.15: This will eventually trigger an error and is now a known issue, with expected behavior listed as “TBD”. So as I expected, its not known whether this will be a supported use case or not. Using a fast lookup / update this... Continue →