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

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

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

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 someday!

 
34
Kudos
 
34
Kudos

Now read this

scheduled flows + visualforce email templates

Many options exist to notify folks about salesforce data. I classify them as ‘popcorn’ (email alerts / chatter posts / notifications via workflows/flows/processes) or ‘consolidated’ (report subscriptions, that random opportunity email... Continue →