Last Updated on February 10, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
How your users can automatically follow records when the records meet specific criteria?
Within Salesforce, users can Follow and Unfollow records by clicking on the Follow icon on the record’s Detail page. If you want to automate the Follow/Unfollow process based on some criteria, then you have to use an AppExchange App or build your own app by using Apex code.
In this article, I will show how you can build this type of functionality without using any code. This is the first article in this series where I will discuss how to automatically follow records. In the next article, I will discuss how to automatically unfollow records.
Objectives:
This blog post will help us to understand the following:
- Learn about Entity Subscription and how to use it
- Create a Record-Triggered Flow to automatically follow records based on criteria
- Learn how to use a Decision element to find whether a Record variable or a Record collection variable contains a record
- Find out how to use the Loop element to extract records from a record collect
- And, last but not least, discover how to use the Create Records element to create multiple records (add followers to record) at once (Bulk Safe)
Business Use Case
Brenda David is working as a System administrator at Universal Containers (UC). As a part of the Salesforce adoption process, management wants to provide a tool to their employees so that they can define the criteria to auto-follow the opportunity record.
Automation Champion Approach (I-do):
There are a few possible solutions for the above business scenario, but I’ll use After-save Record-Triggered Flow to solve the business requirement.
Check out this article to understand why we are using after-save record-triggered flow for this scenario.
Field Name | Details |
ParentId | The Id of the record or user which the user is following. |
SubscriberId | The Id of the user who is following the record or user. |
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 3 steps to solve Brenda’s business requirement using After-save Record-Triggered Flow. We must:
- Create a custom object to store the user’s preference to follow the Opportunity record
- Salesforce Flow
- Define flow properties for record-triggered flow
- Add a decision element to check if amount change and Opportunity is still open
- Add a get records element to find all preference records
- Add a decision element to check if a preference record exists
- Loop element to extract records from the record collection variable (step 2.2)
- Add an assignment element to construct (record variable) EntitySubscription record
- Add an assignment element to add all comments into a record collection variable
- Add a create records element to add followers to Opportunity (bulk safe)
Step 1: Creating a Custom Object to Store User’s Preference to Follow Opportunity Record
Before we begin, we will need to create an object that will save users’ preferences to auto-follow the opportunity records. I will create an object called Opportunity Follow/Unfollow Preference. You can add or remove fields based on your requirements.
In this case, I want users to automatically follow records based on the Opportunity Amount. Create an object and the respective fields based on the following screenshot:
Field Name | Data Type |
Amount | Currency (11, 0) |
Follower Name | Lookup (User) |
- Click Setup.
- In the Object Manager, type User.
- Select Fields & Relationships, then click New.
- Select Date as Data Type, then click Next.
- Enter Field Label and click the tab key, the API Name will populate.
- As a best practice, always input a description.
- Set the Field-level Security for the profiles, make sure to set this field as read-write.
- Add this field to Page Layout.
- Click Save.
Step 2.1: Salesforce Flow – Define Flow Properties
As we have a requirement of creating records in (EntitySubscription) when an opportunity post is created or updated. This is why we have to use the After-save flow on Opportunity.
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Trigger the Flow When: A record is created or updated
- Run Flow: After the record is saved
- Object: Opportunity
- Select None for Condition Requirement.
- Click Done.
Step 2.2: Salesforce Flow – Using Decision Element to Check if Opportunity is Still Open and Amount Change
Now add the Decision element to check, if opportunity amount is change and it is still open. You can take help from the screenshot below:
- Under Toolbox, select Element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.IsClosed}
- Operator: Equals
- Value: {!$GlobalConstant.False}
- Resource: {!$Record.IsClosed}
- Click Add Assignment
- Row 2:
- Resource: {!$Record.Amount}
- Operator: Is Changed
- Value: {!$GlobalConstant.True}
- Resource: {!$Record.Amount}
- Row 1:
- Click Done.
Step 2.3: Salesforce Flow – Adding a Get Record Element to Find all Opportunity Follow/Unfollow Preference Records
The next step is to get all Opportunity Follow/Unfollow Preference (Opportunity_FollowUnfollow_Preference__c) records that fall under user-defined values with current record. We will use the Get Records element. To do this drag-and-drop Get Records element onto the canvas and map the fields according to the details below:
- Under Toolbox, select Element.
- Drag-and-drop Get Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Opportunity_FollowUnfollow_Preference__c object from the drop-down list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Opportunity_FollowUnfollow_Preference__c | Amount__c
- Operator: Greater Than
- Value: {!$Record.Amount}
- Row 1:
- How Many Records to Store:
- select All record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 2.4: Salesforce Flow – Using Decision Element – Does Opportunity Follow/Unfollow Preferences Records Found?
Now add the Decision element to decide whether or not we found the opportunity follow/unfollow preference records. If the Resource (record collection variable) is null, then it means there was found. You can take help from the screenshot below:
- Under Toolbox, select Element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Get_Follow_Unfollow_Preferences}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- Click Done.
Step 2.5: Salesforce Flow – Loop to Retrieve Records from Collection Variable
- Drag-and-drop the Loop element onto the Flow designer.
- Enter a name in the Label (Loop through Preferences) field – the API Name will auto-populate.
- For Collection Variable select {!Get_Follow_Unfollow_Preferences}.
- For Specify Direction for Iterating Over Collection select the option First item to last item.
- Click Done.
Step 2.6: Salesforce Flow – Add an assignment element to construct (record variable) EntitySubscription
- Create a Record Variable varREntitySubscription of type Entity Subscription to add a follower to the opportunity record.
- Drag-and-drop the Assignment element onto the Flow designer.
- Enter a name in the Label (Construct EntitySubscription field – the API Name will auto-populate.
- Set Variable Values
- Row 1:
- Field: {!varREntitySubscription.ParentId}
- Operator: Equals
- Value: {!$Record.Id}
- Click Add Assignment
- Row 2:
- Field: {!varREntitySubscription.SubscriberId}
- Operator: Equals
- Value: {!Loop_through_Preferences.Follower_Name__c}
- Row 1:
- Click Done.
Step 2.7: Salesforce Flow – Adding Values to a Record Collection Variable
- Create a Record Collection Variable varREntitySubscriptions of type Entity Subscription to store record variable (created in step 2.6) for the bulk process.
- Drag-and-drop the Assignment element onto the Flow designer.
- Enter a name in the Label (Add Records into a Collection) field – the API Name will auto-populate.
- Set Variable Values
- Row 1:
- Field: {!varREntitySubscriptions}
- Operator: Add
- Value: {!varREntitySubscription}
- Row 1:
- Click Done.
Step 2.8: Salesforce Flow – Add a Create Records Element to Add Followers to Opportunity
- Drag-and-drop the Create Records element onto the Flow designer.
- Enter a name in the Label (Create Records from Collection) field- the API Name will auto-populate.
- For How Many Records to Create select Multiple.
- Map Record Collection: {!varREntitySubscriptions}
- Click Done.
In the end, Brenda’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 52
- Interview Label: Record-Triggered After Save: Opportunity Follow {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
- Now create a few records in the object Opportunity Follow/Unfollow Preference to save criteria to Auto Follow records, it will look similar to the screenshot below:
- Update an opportunity record with the amount of $800.
Formative Assessment:
I want to hear from you!
What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?
Make a post and tag me on Twitter @automationchamp, using #AutomationChampion.
Hi Rakesh,
I want to know if this will work for my use case:
How to automatically “Follow” in Chatter for all My Owned Opportunities where the campaign source is let’s say ‘Field Connect’.
User wants to automatically follow the record which has been assigned to user.
Please advise
Hi Rakesh,
So every time user changes amount on the opportunity Object, the flow will fire which will check if the amount on the preference object is greater than the ,amount on the Opportunity object. if it is then ensure that user follows the opp record….
What will happen if the amount on the opportunity object changes few times then the flow will try to subscribe same user to the opp record couple of times which should throw an error…..Am I correct or missing something here?
Yes, you’re right. If you want to avoid such an error, add additional logic to not include existing subscribers.
Hi Rakesh,
If we have multiple users in the picklist on the opportunity object and once the admin selects multiple users for the opp object,then those users will me made to follow a particular opp record…Is there a way to loop through all user names?….Problem is that multiple usernames are stored together separated by a semi colon in a variable……How do i separate them so that i can query user object using user names?
looking to do through After save record trigger
Any suggestions?
Check out this article – Parsing Dynamic choice Multi-Select Picklist fields (Flow) – Reusable compon
Hi Rakesh,
Nice post on flow for auto following the record.
I have a use case wherein the user should auto follow a record when the user name is updated in the field and the user names are maintained in multi pick-list field , so when an admin select the user/s on the record those users should auto follow the record.
Could you please let me know how can this be achieved??
We don’t need a custom object for this.
Thanks,
Harsha
You don’t need to ma a new custom object for this purpose. Here are my suggestions:
1. Store newly select username in a Variable
2. Then find the USerID using Record Lookup element
3. Use Record Create element to create a new follower
I tried this but it isn’t working for me. I want a user called Sales RD to follow cases for their accounts. Note they are not the account owners but the user lookup field is on the account. I also could not start the flow with workflow rule but had to add a process builder.
First, you’re right. Use Process Builder instead of Workflow Rule.
Second, make sure that you have setup it correctly. Did you get any error?
No error at all. I can email you what I created it that works for you.
If you wanted to auto create a subscription based on Account Team member to follow Account, could you do that all in Process Builder? New Account Team member = new subscription? I’m following your steps, but it doesn’t appear to be working. I am trying to customize it for any Account Team member auto follow. Any thoughts where this would change for this scenario?
Yes, it should work. But it will also depend on your process design. Can you please share your process n flow at info@automationchmapion.com
Hi Rakesh,
My Business case is: Opp Owner Manager, Manager’s Manager and VP (third in the role hierarchy) auto Follow the Opp record based on:
Amount>100k, Forecast Cat = Commit and Closed Date = This Quarter.
I’m not sure why I need to create the custom Object “Opp Follow”? Should I create custom lookups to the Opp for each condition?
Isn’t a way to create a PB on the Opp Object to define the criteria and autolaunch the Flow?
Can you advise how the Flow will look like in this solution? (considering I can map the OppID and the ManagerID Variables from the PB)
The Flow only needs to check if the Manager already Follows the Opp record and if not then to create an Entity Subscription ID. If the Manager does Follows the Opp then to do nothing.
Any help? 🙂
You should with the help of Flow and Process Builder.
Just wondering why this entire thing cant be done in Process Builder. It looks like it needs a combo of Process Builder and Flow. What is it about the Flow that cant be done in Process Builder?
You are right here, we have to use both Flow and Process Builder. We can’t implement it using Process builder, because it doesn’t allow us to store record id….For example store the record ID
Hi Rakesh,
I am on step 4. When I type {!Amount} or {!OwnerID}, it says “The merge field does not exist” so I can’t carry on…can you please help me?
Sorry for the confusion, you have to first create these variables
Amount
OnwerID
SubscriberID
ExistorNot (SObject Variable)
SingleID (SObject Variable)
Ids(SObject Collection Variable)
MassAdd (SObject Collection Variable)
As shown in the following screenshot
https://rakeshistom.files.wordpress.com/2014/07/variables.png
Thanks!
Your welcome 🙂
Hi Rakesh,
I am walking through this tutorial and when I get to step 4, the “Ids” sobject collection variable (of type EntitySubscription, Input/output type: Input & Output) is not selectable in the variable list. If i change it to “opportunity type”, it shows up. But based on your step 3 graphic, it looks like “singleid” and “id” supposed to be EntitySubscription type…. can you please clarify description of step 3 variables? thanks very much for the tutorial.
Ids and SingleId :- Opportunity Type
ExistorNot and MassAdd :- EntitySubscription Type
Hi Rakesh, Thanks for quick reply,
I am new in salesforce, can you show me some steps to do that with Process builder?
From step 6 (i.e. workflow Rule2) you have to migrate it to Process Builder, follow the below steps for more details
1) Navigate to Setup | Build | Create | Workflow & Approvals | Process Builder and click on the New button to create new Process
2) Enter the Process Name, Description and API Name, Once done click on Save button as shown in the following screenshot
https://rakeshistom.files.wordpress.com/2015/02/create-new-process.png
3) Now Click on Object then Select the Opp Follow Object and Evaluation Criteria for Process, as shown in the following screenshot
https://rakeshistom.files.wordpress.com/2015/02/create-new-process1.png
Once done click on Save button
4) Next step is to add Process Criteria, To do that Click on Add Criteria, Please refer to the following screenshot for more details
https://rakeshistom.files.wordpress.com/2015/02/add-proces-criteria.png
Once done click on Save button.
5) Next task is to add one Immediate Actions, i.e. Launch a Flow, Please refer to the following screenshot for more details
https://rakeshistom.files.wordpress.com/2015/02/add-immediate-action.png
Once done click on Save button.
6) Final Step is to add one field update Immediate action, We will use update a record action in the Process, Please refer to the following screenshot for more details
https://rakeshistom.files.wordpress.com/2015/02/update-start-field-to-false.png
Once done click on Save button.
7) Finally your Process will look like the following screenshot
https://rakeshistom.files.wordpress.com/2015/02/prcoes.png
8) Activate the Process. After you activate a process, you can no longer edit that process
Hi Rakesh, i wanna create an rule that a manager will automatically follow all opportunity that have by their team role.
I have been follow all step as your direction,
and at last step i dont found flow trigger in workflow immediate action, any solution to do that?
Thanks
Flow trigger is under Pilot program, You can ask your Account Executive to get in touch with Salesforce.com support to enable it your org. Else you can use Process Builder for fire/call the Flow.