Getting Started with Salesforce Flow – Part 37 (Auto Remove Followers From Closed Opportunity)

Getting Started with Salesforce Flow – Part 37 (Auto Remove Followers From Closed Opportunity)

Last Updated on January 4, 2021 by Rakesh Gupta

To understand how to solve a similar business use case using Process Builder. Check out this article Getting Started with Process Builder – Part 29 (Auto Remove Followers From Questions With Best Replies).

Big Idea or Enduring Question:

How do you automatically remove followers from closed opportunities?

In Salesforce a user can follow Chatter groups or Records. The chatter group manager can add or remove users to the group, for this Salesforce provides out-of-the-box functionality. To manage Follower on the record Salesforce does not have any inbuilt functionality, for example, a rule to auto Add or remove users to records.

On Chatter, a user can follow a maximum of 500 Peoples, topics, and records. To effectively manage Chatter, an organization has to use some automation to auto-unfollow records. If you want to increase this limit log a support case with Salesforce support. 

Objectives:

After reading this article, the reader will be able to:

  • Use After-save Record-Triggered Flow to remove the followers from closed opportunities 
  • Use After-save Record-Triggered Flow Delete element to delete the record(s)
  • Use a Decision element to find – record variable or record collection variable contains a record or not

Business Use case

Steven Greene is working as a System Administrator at Universal Containers (UC). He has received a new requirement to auto-remove the followers from closed opportunities. 

Automation Champion Approach (I-do):

While this can be solved using various automation tools like Apex or Flow, we will use After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Before proceeding ahead, you have to understand EntitySubscription objects in Salesforce. It represents a subscription for a user following a record or another user.

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 to go through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 4 steps to solve Steven’s business requirement using After-save Record-Triggered Flow. We must:

  1. Define flow properties for record-triggered flow
  2. Add a get records element to find opportunity follower(s)
  3. Add a decision element to check the id from the record collection variable (from step 2)
  4. Add a delete records element to remove the follower(s) from the opportunity 

Step 1: Salesforce Flow – Define Flow Properties 

As we have a requirement to remove the records from (EntitySubscription) when an opportunity is closed. This is why we have to use the After-save flow on Opportunity.

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Record-Triggered Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Trigger the Flow When: A record is created or updated
    3. Run Flow: After the record is saved
    4. Object: Opportunity
  5. Select All Condition Are Met (AND)
  6. Set Conditions
    1. Row 1
      1. Field: Opportunity | IsClosed
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  7. Click Done.

Step 2: Salesforce Flow – Adding a Get Record Element to Find Opportunity Follower(s)

The next step is to find the opportunity follower(s). To do that follow the below instructions:

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the Entity Subscription object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: ParentId
      2. Operator: Equals
      3. Value: {!$Record.Id}
  7. How Many Records to Store:
    1. select All records
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 3: Salesforce Flow – Using Decision Element to Check the Record Collection Variable (from step 2)

Now we will use the Decision element to check the Record Variable from step 2 to find if it returns the question followers id or not. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Find_Opportunity_Followers}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 4: Salesforce Flow – Add a Delete Records Element to Remove Followers From Opportunity 

  1. Drag-and-drop Delete Records element onto the Flow designer. 
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Delete select Use the IDs stored in a record variable or record collection variable.
  4. Set Record(s) to Delete
    1. Record or Record Collection: {!Find_Opportunity_Followers}
  5. Click Done.

In the end, Steven’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 51
  5. Interview Label: Remove Followers From Opportunity {!$Flow.CurrentDateTime}
  6. Click Save

Almost there! Once everything looks good, click the Activate button.  

Proof of Concept

  1. Navigate to the Opportunity tab, identify the Opportunity, and click on its name.
  2. Currently, the follower count is 2.
  3. Update the Stage to Closed Won. As soon as you’re done, refresh the page and check the follower count.
  4. The follower count is now at 0.

Formative Assessment:

I want to hear from you!   What is one thing you learned from this post?

How do you envision applying this new knowledge in the real world? 

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

9 thoughts on “Getting Started with Salesforce Flow – Part 37 (Auto Remove Followers From Closed Opportunity)

  1. Thank you very much for the detail instruction. With help of the example, I have successfully built a app which can help user automatic follow account if the user is the owner of the Account. But could you kindly tell me how can I automatic un-follow when the user is not the owner of the account. In the real business because the company structure may change,so the owner may change. And meanwhile a sales is in charge of many account. So we need a automatic way.

  2. Rakesh, It would be really helpful if you could include screenshots of the variable screens for both OppId and OppSubcribersID. This is still new to me, so it helps to see the setup completely so I can understand what’s going on. I understand, though, that you probably want to limit the size of the page.

  3. This is a great article and extremely helpful for something similar I’m working on.

    I’m a little confused about a couple of things:

    1. What step in the workflow actually passes the Opportunity ID to the OppId variable?
    2. I noticed that in the Fast Lookup step, you reference “{!OppID.Id}” in the criteria. What is this? You created a variable called OppID, but not one called OppID.Id, correct?

    Thanks for writing such a useful blog!

    1. It’s not possible to enable this feature in your developer org, but if you are using paid edition than raise a case with salesforce.com support and nominate your organisation for this pilot feature

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.