Last Updated on April 15, 2019 by Rakesh Gupta
In the last article Auto Follow and Auto Unfollow records based on Criteria – Part 1, I have gone through the way to automate Follow records process based on user defined criteria. In this article, I will discuss a way to automate Unfollow records based on criteria.
Business Use Case
Higher management at Universal Container wants to a develop an App for Auto Unfollow Opportunity records based on user defined criteria.
Solution for the above business requirement
First of all create one object to save condition to auto Unfollow records. In this demo I will create an object called as Opp Unfollow to Unfollow Opportunity object records. You can Add/Remove fields as per your requirement. I want to give the option to my users to auto Unfollow records based on Opportunity Owner and Amount. Create object and field as per the below screenshot
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_Unfollow__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 = False it means user is following those records
8) 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 {!Del} so at the end of for loop it will delete all records from EntitySubscription object. Take the help from the below screenshot
9) Finally drag and Drop Fast Delete (Give the name Delete all records) on the window to delete the records from EntitySubscription object, so user will Unfollow those records, as shown in the below screenshot
10) Finally our flow will look like the below screenshot
11) Save the flow with name (Auto Unfollow Opp) and close the canvas.
Create Workflow rule to fire our Flow
Our next task is to create a workflow on the Opp_Unfollow_c object on creation and every time it’s edited event. To create a workflow on the Opp_UnFollow_c object follow the below instructions
1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | New Rule
2) Select object Opp_Unfollow_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 to set Start/Stop flag True after 1hr 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 1hr 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. workflow2 ) 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 Unfollow Opp) 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 Unfollow to save criteria to Auto Unfollow 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
4 thoughts on “Auto Follow and Auto Unfollow records based on Criteria – Part 2”
Melissa VanDyke
Hi Rakesh! I just finished up creating auto follow and auto unfollow objects per this design (using for a custom project management object instead of opps so our boss auto follows everything and then is removed once the status is closed!). Waiting to see if the time based flows work, they are in the queue so hopefully my flows are right 🙂 Thanks so much for these detailed instructions, they were easy to follow!!
Rakesh Gupta
Thank you so much for your comment Melissa!
Melissa VanDyke
Rakesh – I might have messed something up with the loop or workflow? Everything worked great yesterday, the auto follow was confirmed and the auto unfollow was completed, but now it seems that it keeps looking for more record to unfollow and there are none… do you know what I did wrong? Thanks!!
Sandbox
Encountered unhandled fault when running process AutoUnfollowProjects/301110000004LRL exception by user/organization: 00D110000007sqT/{4} Source organization: 00D6000000072fJ (null) DELETE — There is nothing in Salesforce matching your delete criteria
caused by element : FlowRecordDelete.Delete_all_records
caused by: DELETE — There is nothing in Salesforce matching your delete criteria
Salesforce Error ID: 1611219639-38560 (-1205603607)
Rakesh Gupta
Thanks Melissa. Do one thing before Fast delete add one decision element and check if Sobject collection {!Del} not equal to null then only perform the deletion operation else skip it.