Few months back, I had written an article Add/Remove follower to record with Visual Workflow to discuss a way through which we can add or remove Chatter followers to account record. As you all know Flow runs in user mode, it means the Flow we had developed will only work for System administrators or users with the Modify All Userspermission. There are few business scenarios where business wants some workaround so that Flow will work for all the users (Only for users who have edit access on Account). First of all I want to say thanks to Adam Plocki for asking such a great question on Success Community. Let’s start with a business use case
Business Use case :- Warren Mason is working as System administrator in Universal Container. He received a requirement to develop an application, that will allow users (For those, who have edit access on account object) to add Chatter followers to record.
Solution of above business requirement
There are few solutions possible for the above business scenario. We will use Flow and Process Builder (because it runs in system mode) to solve the above business requirement. The advantage of using Flow with Process builder is, you don’t have to assign Force.com Flow User feature license to the users. Before proceeding ahead, you have to understand EntitySubscription object in Salesforce. It’s Represents a subscription for a user following a record or another user. User can subscribe to a record or to another user.
Field Name | Details |
ParentId | ID of the record or user which the user is following |
SubscriberId | ID of the User who is following the record or user |
Follow the below instructions to create a Flow and Process Builder to solve the above business requirement
1. First of all create a Custom field Add Follower (Data Type :- Lookup (User)) on the Account object. We will use this field in the Flow and Process Builder.
2. To create a Flow, click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
3. Click on New Flow, it will open Flow canvas for you. Now we have to create a two variables. First create a Text variable AccountId to store the accountId (we will pass the account Id through Process Builder) as shown in the below screenshot
2. To create a Flow, click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
3. Click on New Flow, it will open Flow canvas for you. Now we have to create a two variables. First create a Text variable AccountId to store the accountId (we will pass the account Id through Process Builder) as shown in the below screenshot
Second Variable FollowerID is used to store the user Id, whom you want to add as a Chatter follower to record.
4. To add a Chatter follower to record, drag-and-drop a Record Create ( Give the name Auto add follower to record) onto the window and map the fields according to below details
- Select Object EntitySubscription
- Enter Assignment ParentId= {!AccountId} and SubscriberId= {!FollowerID}, as shown in the below screenshot
5. Finally your Flow will look like the following screenshot
6. Save your flow with name Add Chatter follower to record PB and close the canvas. Don’t forget to Activate the Flow.
Launch a Flow from Process Builder
Our next task is to create a Process on the Account object to launch a Flow. To create a workflow on the Accountobject follow the below instructions
1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder and click on the Newbutton, Enter Name, API Name and then click on the Save button
2. The next step is to add entry criteria. For this click on Add Object, select Account object and for the entry criteria, Select when a record is created or edited, as shown in the below screenshot, once you are done click on the Savebutton
3. The next task is to add Process Criteria, To do this click on Add Criteria, enter Name, Type of action and set filter conditions (In this case set [Account].Add_Follower__c Is Changed True) and click on the Save button, as shown in the following screenshot
4. The next step is to add an Immediate action to Process. Click on Add Action (Under Immediate actions), Select the type of action to create (In our case Flows) , and then fill out the fields to define the action, as shown in the following screenshot
5. Once you are done, click on the Save button, it will redirect you to Process canvas. Finally the Process will look like the following screenshot
Don’t forget to active the Process by clicking on the Activate button.
It’s time to test this App
1) Now LoggedIn through a business user account. In this demo I am going to use Demo User account (Profile assigned:- Standard User, Force.com Flow User feature license is not assigned to this user ).
2) The next step is to edit the record and populate the Add Follower field as shown in the following screenshot
Finally checkout the Follower section available on the record detail page.
Note :- I will suggest you to implement this first on your developer org test it and then move it to Production.
Post a Comment