Using Flow to Post to Chatter with Attachment

Using Flow to Post to Chatter with Attachment

Salesforce Chatter allows real-time information sharing and collaboration. It acts like a social media newsfeed, with interactive threads for posts. Users can post to Chatter, and others can comment, like, or share. Moreover, users can mention others and link records too. This makes Chatter a very useful tool for the users. There are multiple ways to post to Chatter using Salesforce Flow. While these methods lack the ability to attach files, it is still possible to use the out of the box Flow elements to post to Chatter with attachment.

Using the Create Records Element to Post to Chatter

Feed Item is the object that represents the Chatter posts. It is possible to use the Create Records element to create a Feed Item record. Parent Id field means the Target Id (user, group, or record Id) and Body field is the message that you want to post. It is possible to post a rich text message as well. In order to do so, prepare a text template with HTML tags and set IsRichText to true.

Read this official article to learn more about the remaining fields of the Feed Item object.

After creating the Feed Item record, the system will publish your message as a Chatter post.

Using Flow to Post to Chatter

Feed Item object is for the Chatter post only. There is no option to add an attachment in the Feed Item object. However, it is possible to use the Feed Attachment object to add attachments to the Chatter post.

Using the Feed Attachment Object

Feed Attachment object, which is a child object of Feed Item, represents the attachments related to a Chatter post. There are a few fields that you will need to map here.

Feed Attachment Type = Content
Feed Entity ID = Id of the Feed Item
Attachment Record ID = Id of the Content Version

Using Screen Flow to Post to Chatter with Attachment

Let's build a screen flow to post to Chatter with attachment.

1- Add a Screen element with a long text field for the message. Then, add a File Upload component for the attachments. Optionally, allow uploading multiple files.

Screen for Data Entry

2- Let's assume that we are launching this screen flow from a Case record. Add a Create Records element to create a Feed Item record. Pay attention that recordId is a Case record variable.

Create Feed Item Record

3- Now it is time to attach the files to the Chatter post. Since the output of the File Upload component is a text collection, we have to use Loop and Assignment elements.

Add a Loop element and then use an Assignment element to assign the Feed Attachment records.

Assign Feed Attachment Records

4- At the end of the flow, use a Create Records element to create the Feed Attachment records.

At the end, after adding fault paths, your flow should look like this.

End of the Flow

As you can see, the flow created a Chatter post with 2 attachments.

Chatter Post with Attachments

In this post, we built a simple screen flow to post to Chatter with attachment. You can apply the same logic in a record-triggered flow to automate the process. Alternatively, you can also post on the Chatter feed of users.

Be the first to comment

Leave a Reply

Your email address will not be published.


*