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