Add or Remove Followers to a Record with the Help of Salesforce Flow

Add or Remove Followers to a Record with the Help of Salesforce Flow

Last Updated on February 10, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How can we develop declarative functionality to add or remove followers from a record?

In Salesforce, a user can follow Chatter groups or Records. Salesforce provides out-of-the-box functionality so that Chatter group managers can also add/remove people from the group. To manage a record’s followers/subscribers, Salesforce does not have any pre-built functionality to add or remove a follower/subscriber from object records.

Objectives:

After reading this article, you will be able to:

  • Use Flow to manually add or remove users as subscribers from a record
  • Understand the component visibility option to create a highly dynamic screen 
  • Learn how to use a Decision element to find whether a Record variable or a Record collection variable, contains a record
  • And, last but not the least, discover how to add a Flow to Lightning Record Page and display it to a set of users 

Business Use Case 

Elise Shelley, a Lead System Administrator at Universal Containers (UC) receives a requirement from his management, they want to develop an application for the user with the role of Direct Sales Director so that they can use it to add or remove followers/subscribers to Account records.

Automation Champion Approach (I-do):

First of all, I want to say thanks to Andrew Johnson for sharing his idea (7 years ago) and flow (Add follower to record), which he shared in the success community. In this blog, we will use Salesforce Flow to solve the above business requirement. My main aim is to show the various ways to use Salesforce Flow in your organization.

While this can be solved using various automation tools like Apex, etc, we will use Screen Flow.

Before proceeding ahead, you have to understand the EntitySubscription object. The object represents a user‘s subscription – whether the user follows a record or other users. A user can subscribe to a record or to another user.

Field Name Details
SubscriberId The Id of the User who is following the record or user.
ParentId The Id of the record or user which the user is following.

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 3 steps to solve Elise’s business requirement using Screen Flow. We must:

  1. Salesforce Flow Steps: Define flow properties 
    1. Create a text variable to store account Id
    2. Add a screen to capture the user’s input
      1. Add a radio buttons to show two options
        • Add Follower
        • Remove Follower 
      2. Add a lookup component to display all Users 
        1. Add component visibility to show lookup component for add follower option (from step 1.2.1.1)
      3. Add a picklist component to display the account followers
        1. Add component visibility to show picklist component for remove follower option (from step 1.2.1.1)
    3. Add a Decision element to check if user has been selected to add or remove a follower
    4. Add a Get Records element to find the account subscriber detail
    5. Add a Decision element to check if the record variable (from step 1.4) is null or not
    6. Add a Create Records element to add a user to account follower
    7. Add a Delete Records element to remove a follower from the account 
  2. Create a Quick action to launch the flow
  3. Add quick action to the lightning account record page and add filter criteria

Step 1: Salesforce Flow – Define Flow Properties   

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 1.1: Salesforce Flow – Add a Text Variable to Store Account Id

  1. Under Toolbox, select Manager, then click New Resource to store the current account record Id 
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: recordId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.2: Salesforce Flow – Add a Screen Element  

  1. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 1.2.1: Salesforce Flow – Add a Radio Buttons Component to Capture the User Selection for Add Follower vs Remove Follower 

  1. Under Input section on Screen Element. Drag and drop the Radio Buttons component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Data Type: Text
    3. Under Select Choices
      1. Choice 1: Add Follower
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: AddFollower
        4. Choice Label: Add Follower
        5. Data Type: Text
        6. Choice Value: Add Follower
        7. Click Done.
      2. Add Choice
      3. Choice 2: Remove Follower
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: RemoveFollower
        4. Choice Label: Remove Follower
        5. Data Type: Text
        6. Choice Value: Remove Follower
        7. Click Done.
  3. Click Done.

Step 1.2.2: Salesforce Flow – Add a Lookup Component to Display All Users

It’s time to add a Lookup Component to capture the user whom they want to make a follower of the record. For this, we will use the lookup component.

  1. Under Input section on Screen Element. Drag and drop Lookup onto the screen. 
  2. Input the following information:
    1. Enter API Name.
    2. Field API Name: CreatedById (Enter the field API Name that will show up in the list box to represent a record.)
    3. Label: Select a Follower (Enter a label that appears next to the lookup control)
    4. Object API Name: Account ( Enter the object API name) 
    5. Required: {!$GlobalConstant.True}
  3. Click Done.

Step 1.2.2.1: Salesforce Flow – Add Component Visibility to Conditionally Display Select User Lookup Component 

You can control when screen components appear with conditional visibility. In the current scenario, we want to display the Select User lookup component only when the user has selected the Add Follower option.

  1. Under the Lookup Component expand the Set Component Visibility section. 
  2. Now we will define the conditions for when the lookup component is visible.
    1. When to Display Component: Custom condition Logic Is Met
  3. The next step is to define the filter logic if you entered multiple conditions.
    1. Resource: Screen Component >> {!Select_Option}
    2. Operator: Equals
    3. Value: CHOICES >> {!$AddFollower}
    4. Click Done
  4. Click Done.

Check out this article Dynamic Flow Screen – What is Not to Love? to learn more about component visibility. 

Step 1.2.3: Salesforce Flow – Add a Picklist Component to Display the Account Followers 

  1. Under Input section on Screen Element. Drag and drop the Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Under Select Choices 
      1. Click + New Resource, it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: AccountFollowers
      4. Object: Entity Subscription
      5. Filter Entity Subscription Records
        1. Row 1:
          1. Field: ParentId
          2. Operator: Equals 
          3. Value: {!recordId}
      6. Configure Each Choice
        1. Choice Label: SubscriberId
        2. Data Type: Text
        3. Choice Value: Id
      7. Click Done
  3. Click Done.

Step 1.2.3.1: Salesforce Flow – Add Component Visibility to Conditionally Display Select Follower Picklist  

You can control when screen components appear with conditional visibility. In the current scenario, we want to display the Select Follower Picklist component only when the user has selected the Remove Follower option.

  1. Under the Picklist Component expand the Set Component Visibility section. 
  2. Now we will define the conditions for when the lookup component is visible.
    1. When to Display Component: Custom condition Logic Is Met
  3. The next step is to define the filter logic if you entered multiple conditions.
    1. Resource: Screen Component >> {!Select_Option}
    2. Operator: Equals
    3. Value: CHOICES >> {!$RemoveFollower}
    4. Click Done
  4. Click Done.

Step 1.3: Salesforce Flow – Using Decision Element to Check if a User has been Selected to Add Follower or Remove Follower Option 

Now we will use the Decision element to check if the user who is using the Flow has been selected to add follower vs remove follower option. This will help us to branch out our logic for Add vs remove section. 

  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 (Add Follower) the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Select_Option}
      2. Operator: Equals
      3. Value: {!AddFollower}
  6. Under Outcome Details, click on the +
  7. Enter the Label (Remove Follower) the API Name will auto-populate.
  8. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Select_Option}
      2. Operator: Equals
      3. Value: {!RemoveFollower}
  9. Click Done.

Step 1.4: Salesforce Flow – Adding a Get Record Element to Find the Selected User Subscriber Details for Current Account 

The next step is to use the EntitySubscription object to check whether the selected user is already following the current account or not.

  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. Id: SubscriberId
      2. Operator: Equals
      3. Value: {!Select_User.recordId}
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 1.5: Salesforce Flow – Using Decision Element to Check the Record Variable (from step 1.4)

Now we will use the Decision element to check the Record Variable from step 1.4 to find if it returns the record 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_Subscriber}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 1.6: Salesforce Flow – Create Records – Add a Follower to Account 

The next step is to create a new follower to account. For this will use the Create Records element. 

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: EntitySubscription
    5. Set Field Values for the Entity Subscription 
      1. Row 1:
        1. Field: ParentId
        2. Value: {!recordId}
      2. Add Field
      3. Row 2
        1. Field: SubscriberId
        2. Value: {!Select_User.recordId}
  3. Click Done.

Step 1.7: Salesforce Flow – Add a Delete Records Element to Remove a Follower From the Account 

  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 Specify conditions.
  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: Id
      2. Operator: Equals
      3. Value: {!Select_Follower}
  7. Click Done.

In the end, Elise’s Flow will look like the following screenshot (I turned on Auto-Layout) for this flow: 

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. How to Run the Flow: System Context Without Sharing-Access All Data 
  5. Type: Screen Flow
  6. API Version for Running the Flow: 51
  7. Interview Label: Add or Remove Record Followers {!$Flow.CurrentDateTime}
  8. Click Save

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

Step 2: Create a Quick Action – Add/Remove Follower 

The next step is to create a quick action Add/Remove Follower) on the Account object to call the Flow. Salesforce will automatically pass the value to recordId variable. 

  1. Click Setup.
  2. In the Object Manager, type Account.
  3. Select Buttons, Links, and Action, then click New Action.
  4. Input the following information:
    1. Select Flow as Action Type.
    2. Select Add or Remove Record Followers as Flow.
    3. Enter Label (Add/Remove Follower) the Name will auto-populate.
  5. Click Save.

Step 3: Add Quick Action to Account Lightning Record Page and Add Filter Criteria 

The next step is to distribute a flow to Lightning Experience or Salesforce app users, by embedding it in the Account Lightning record page.

  1. Click Setup.
  2. In the Object Manager, type Account.
  3. Select Lightning Record Pages, click on the Label to open the page.
  4. Click on the Edit button to open a Lightning page in the Lightning App Builder.
  5. Make sure to enable the Dynamic Action for Account. 
  6. From the Highlights Panel
    1. Click Add Action
    2. In the Actions modal, choose an action i.e. Add/Remove Follower, as shown in the following screenshot:
  7. Set Filter Conditions
  8. Click + Add Filter
  9. Row 1:
    1. Field: Record > Account Owner > Role > Developer Name
    2. Operator: Equal
    3. Value: DirectorDirectSales
  10. Click Done.
  11. Once everything looks good, click the Save button. 

Proof of Concept

Now Onwards, a user with the role of Direct Sales Director can use this application to add remove followers from the account record. 

  1. To add a follower to the record, navigate to the Accounts tab and click on any Account Name to open its detail page
  2. Click on the Add/Remove Follower button and perform the steps, as shown in the video:
  3. The subscriber will be added as a Follower, and you will be redirected to the Account detail page.

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 #AutomationChampionFlow.

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

14 thoughts on “Add or Remove Followers to a Record with the Help of Salesforce Flow

  1. Great flow Rakesh!
    Do note that it will not allow the active user to follow the record via the flow, only via the dedicated standard button on the record.
    Also, looking for a way to show the User’s Full Name in the “Remove Followers” Choice Set instead of the ID.

    Any help greatly appreicated.
    Thanks!

  2. Hi Rakesh, I configured above flow for adding Followers. But my scenario is – There are multiple person having same name but different Profile. So on screen 2 along with User Name I also want to display users profile beside name. Plz suggest How to do it?

  3. Hey..
    I was trying the adding follower option but getting error while creating records i.e. on step-4.

    RECORD CREATE: Auto_Add_Follower_To_Record
    Create one EntitySubscription record where:
    ParentId = {!AccountID} (null)
    SubscriberId = {!AddFollowerIDNew} (0056F000006DOkGQAW)
    Result
    Failed to create record.

    I’m unable to figure out why AccountID/ParentId is coming out as NULL..

    Please guide me for the same,

Leave a Reply

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