Skip to main content

I've set up a flow that sends a chatter post whenever an email-to-case comes in. Now I want to use the flow to add any possible attachments to the chatter post. Is this possible with just a flow? 

 

#Flow  #Chatter

1 answer
  1. Sep 9, 3:45 PM

    Hi Terry, 

     

    Yes, this is possible with pure declarative Flow, no Apex needed. Here's how it fits together: 

     

    Background:  

    Email-to-Case attachments are stored as ContentDocument/ContentVersion records, linked to the EmailMessage record via ContentDocumentLink (LinkedEntityId = the EmailMessage's Id), not as old-style Attachment records. Chatter posts (FeedItem) can't hold files directly either, they need a FeedAttachment junction record pointing to a ContentVersion. 

    Official reference:

    https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm

     

     

    Flow structure: 

     

    1. Trigger: Record-Triggered Flow on EmailMessage (After Save), or continue from wherever your current flow starts (Case creation via Email-to-Case). 

     

    2. Get Records: query ContentDocumentLink where LinkedEntityId equals the EmailMessage's Id. This gives you the ContentDocumentId(s) of any attachments on that email. 

     

    3. Get Records: query ContentVersion where ContentDocumentId is In your collection from step 2, and IsLatest = true. This gets you the actual file version records you'll attach. 

     

    4. Create Records: create your FeedItem (Chatter post) as you're already doing, on the Case. 

     

    5. Create Records: for each ContentVersion found in step 3, create a FeedAttachment record with: 

       - Feed Entity ID = the FeedItem Id created in step 4 

       - Attachment Record ID = the ContentVersion Id from step 3 

       - Type = Content 

     

    This is exactly the declarative pattern documented for Flow-built Chatter posts with attachments. Reference (community-verified build with the same object structure):

    https://developer.salesforce.com/docs/atlas.en-us.200.0.chatterapi.meta/chatterapi/quickreference_post_feed_element_content.htm

     

     

    One sequencing note: the FeedItem must be created and its Id known BEFORE you can create the FeedAttachment, so make sure your Flow creates the FeedItem in a separate Create Records element (not bulkified together with FeedAttachment), then use the created FeedItem's Id in the following FeedAttachment creation step. 

     

    This works entirely with standard Flow elements, get records, create records, no Apex required.

0/9000