Automated Chatter Posts in Salesforce Communities with Process Builder and Flow: A Collaboration Story
The Story
All we wanted to do was @-mention a Community user on a record in the Community to alert them to take a simple action. We already had a successful bustling Communities implementation rolling along for our client, where members of the Community had become accustomed to leveraging Chatter to communicate within the Community with each other and with the internal staff at the organization. When the use case came up to generate records that required attention of Community members, Chatter was the natural choice to alert them, keeping all the back-and-forth nicely within the Community.
Familiar with automating robust chatter posts inside a Salesforce organization, we immediately turned to Process Builder. It seemed like it should be so simple--just build a Process that would run when these records are created with a Post to Chatter Action. We had the relationships in place to be able to mention the correct user in the post and everything. But when we built this automation, we found a limitation: because this Process was being kicked off internally to the Salesforce organization, the post was visible on the record for internal users but not visible in the Community, even if it successfully @-mentioned the Community user.
So how could we get this post to be in the Community, not the internal Salesforce organization? We know a lot of stuff, but not everything, and so we turned to the Trailblazer Community for help, posting this use case and question through Answers. Within a couple days we got a response--there was a way! Gaurav Malik, our hero, promised, with Flow. Lesson? Don’t be shy about asking questions! Even the experts do it. All the time, in fact. Salesforce is a huge platform; it is impossible to know every little thing, and learning and helping each other with solutions is part of what makes this such a great platform to work on. Plus once your question is answered, that solution is out there for others to find and use.
The answer from the Trailblazer Community put us on the right path, but we still had to figure out all the details of how to get this Flow to work, and some of the inputs we saw in the screenshot from our hero needed a bit more context. We turned again to the Trailblazer Community, this time searching the Help articles for a reference on the Post to Chatter Element in Flow, and then to a good old fashioned Google search to turn up a blog post on how to get the Community ID. So in true Arkus style of giving back, we are putting together all these resources into a summary of the solution for the next person to find and use.
The Solution
Implementing the solution was actually quite simple, once we had all the information. First, we created a Flow. This flow had a single Post to Chatter Element as its only step.
The key was to set the Community ID to the ID of the Community where the post should appear and the Visibility to “allUsers” (the alternative being “internalUsers”) so it can be seen by Community users. The actual visibility of any individual resulting post is still under whatever layers of security are on the the Target item.
Our Flow also included a Text Template to assemble the contents of what we wanted to post, which was necessary to get the merge field in of the user we wanted to mention along with some standard text. We used this as the message body in the Post to Chatter Element.
We defined variables in the Flow for the Record ID of the record we want the post to be on to be used in the Target input for our Post to Chatter element and for the User ID to be used in our Text Template to mention the user with the syntax @[{!id-goes-here}]. Both are Data Type “Text” and, importantly, Input/Output Type “Input and Output.” These variables will get populated by our Process. That ‘feedItemId’ is just the required output of the Post to Chatter element. No need to actually have to do anything with it, or worry about the warning message that comes up when saving the Flow that the Post to Chatter Element isn’t attached to anything (though adding error handling would be even better.)
The Flow was saved and Activated and ready to use in our Process. Our Process was very simple but this could just as easily be part of a more complex set of actions. The important thing is to have an Action in the process to Launch a Flow, where you pass in the variables needed to get the post in the right place and to the right person as described above.
Ready to dive in and do this in your own org? Keep in mind the following prerequisites for it to work:
If posting to a record, Feed Tracking must be enabled on that object. If not, you’ll just get a cryptic error when the Process tries to fire.
The Community user must have access to the place the post is going in order to see the post, so if it is a record, they must have access to the object via profile/permission set and access to the record via sharing model. Lack of this will not prevent the automation from working, but it will prevent the real desired result.
There must be a way to know the ID of the Community user in order to mention them--they could be the owner of a record or in some other way related to the record that sets of the Process or the ID just stored somewhere available to the Process. In our case the ID was stored in a text field on an object a couple steps away, but thanks to the power of field references in Process Builder this was easy to access.
If you try this and have successes or enhancements to add, please do comment on the Salesforce Success Community or directly at me on Twitter @ifitfloats.