Last Updated on April 15, 2019 by Rakesh Gupta
In Salesforce user can Follow and Unfollow records by clicking on icon available on the record detail page. If you want to automate this Follow/Unfollow process based on some criteria then you have to use AppExchange App or build your own app by using Apex code. In this article, I will show how you can build this app without using any code. This is the first article of this series in this I will discuss auto Follow records, In next article, I will discuss auto Unfollow records.
Business Use Case
Higher management in Universal Container wants to a develop an App for Auto follow Opportunity records based on user defined criteria.
Solution for the above business requirement
First of all, create one object to save condition to auto follow records. In this demo, I will create an object called as Opp Follow to follow Opportunity object records. You can Add/Remove fields as per your requirement. I want to give the option to my users to auto follow records based on Opportunity Owner and Amount. Create object and field as per the below screenshot
To solve this requirement we will use Visual Workflow. Before going ahead with the solution you have to understand about EntitySubscription Object. 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 |
To develop this application follow the below instructions
1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
2) Click on New Flow, it will open flow canvas for you
3) First create few Variables as shown in the below screenshot
4) Drag and Drop Fast Lookup (Give the name Get all Opportunities) on the window to get all Opportunity fall under user defined value on record (Opp_Follow__c)
5) Drag and drop a Loop Logic (Give the name Loop over Opportunity) on the window and extract value from Sobject Collection variable and pass it to Sobject variable, as shown in the below screenshot
6) Now Compare with Opportunity id and subscriber id with EntitySubscription object record, to check whether the user is following same opportunity record or not. Save value in variable {!ExistorNot}. Drag and drop a Record Lookup (Give the name Entity Subscription) on the window and take help from the below screenshot
7) Now Drag and Drop Decision element (Give the name Go Ahead or Not) on the window to check whether Sobject variable {!ExistorNot} is null or not null. If the variable is Null = True it means user is not following those records
8) Drag and Drop Assignment Logic (Give the name Assign Subscriber ID) on the window and assign the value to Sobject variable {!ExistorNot} as shown in the below screenshot
9) Drag and Drop Assignment Logic (Give the name All in One) on the window and assign value from Sobject variable {!ExistorNot} to Sobject Collection variable {!MassAdd} so at the end of for loop it will create records in EntitySubscription object to follow records. Take the help from the below screenshot
10) Finally drag and Drop Fast Create (Give the name Create Records) on the window to create the records in EntitySubscription object, to follow the Opportunity records, as shown in the below screenshot
11) Finally our flow will look like the below screenshot
12) Save the flow with name (Auto follow Opp1) and close the canvas.
Create Workflow rule to fire our Flow
Our next task is to create a workflow on the Opp_Follow_c object on the creation and every time it’s edited event. To create a workflow on the Opp_Follow_c object follow the below instructions
1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | New Rule
2) Select object Opp_Follow_c from the drop-down
3) Enter Name, for Evaluate criteria select Created, and any time it’s edited to subsequently meet criteria ( To create a time-dependent workflow), For Rule Criteria select Start/Stop= False as shown in the following screenshot
4) Now Add a time trigger to set Start/Stop flag True after 0hr of record last modification date. To do this click on Add Time Trigger button and Set the length after how many days/hours workflow will fire i.e. in hours and days, I selected 0hr after the Last Modified Date. Now add one field update action for time-dependent workflow and set Start/Stop flag to True. You can take help from the following screenshot
5) Save the workflow and activate it.
6) Create another workflow (i.e. workflow Rule2 ) on the same object to fire our Flow, set entry criteria of trigger is Start/Stop= True
7) Add one Immediate Workflow Actions i.e. New Flow Trigger and Select Flow ( Auto follow Opp1) and set Variable (Amount, OwnerID and SubscriberID) value as shown in the following screenshot
8) Add one Immediate Workflow Actions i.e. New Field Update and Set Start/Stop flag to False, so it will queue the record for the next time.
9) Save the workflow and activate it.
It’s time to test this feature
1) Now create one record in the object Opp Follow to save criteria to Auto Follow records, it will look similar to below screenshot
2) To check time dependent workflow queue Follow the path, Click on Name | Setup | Administration Setup | Monitoring | Time–Based Workflow and search the queue
Auto Follow and Auto Unfollow records based on Criteria – Part 2
Note :- To migrate from Workflow rule to Process builder please see my comment :- https://automationchampion.com/2014/07/18/auto-follow-and-auto-unfollow-records-based-on-criteria-part1/#comment-1705
21 thoughts on “Auto Follow and Auto Unfollow records based on Criteria – Part 1”
Rajendra
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
Rakesh Gupta
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
Mardago
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.
Rakesh Gupta
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?
Mardago
No error at all. I can email you what I created it that works for you.
chrissythompson22
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?
Rakesh Gupta
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
Oded
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? 🙂
Rakesh Gupta
You should with the help of Flow and Process Builder.
chris uttley
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?
Rakesh Gupta
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
Mario
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?
Rakesh Gupta
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
Jennifer
Thanks!
Rakesh Gupta
Your welcome 🙂
Jennifer
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.
Rakesh Gupta
Ids and SingleId :- Opportunity Type
ExistorNot and MassAdd :- EntitySubscription Type
fhadiningrat
Hi Rakesh, Thanks for quick reply,
I am new in salesforce, can you show me some steps to do that with Process builder?
Rakesh Gupta
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
hadif615
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
Rakesh Gupta
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.