Add Chatter Followers to Record

Add Chatter Followers to Record

Last Updated on March 23, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can I allow users to easily add others as followers of a record?
  • Can I incorporate it as part of a new/existing Flow?

Objectives:

This blog post will help us to understand the following

  • Add another user as a follower of a specific record using Salesforce Flow
  • Use a Decision element to find whether a field contains a value or not
  • And, last but not least, discover how to use the Create Records element to create records
  • and much more

Business Use case

Brenda David is working as a System Administrator at Gurukul on Cloud (GoC). She has received a requirement to develop an application that will allow users with edit access on the account object to add Chatter followers to record.

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario. We will use Record-Triggered Flow to solve the requirement.

Flow can be run in System mode, bypassing the running user’s permissions.  For instructions on how to accomplish this same use case with only Screen Flow, refer to this post: Getting Started with Salesforce Flow – Part 42 (Running a Flow in System Mode)

Before proceeding, you should become familiar with the EntitySubscription object in Salesforce. It represents a subscription for a user following a record or another user. A user can subscribe to a record or to 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 2 steps to solve Brenda’s business requirement using After-Save Record-Triggered Flow. We must: 

  1. Creating a custom lookup field on account to store a new follower
  2. Salesforce Flow Steps:
    1. Define flow properties for record-triggered flow
    2. Add a decision element to check the custom lookup field value is not null
    3. Add a get records element to find the status of selected user follower status for current record
    4. Add a decision element to check if user is following the current record or not
    5. Add a create records element to add a user to record follower

Step 1: Creating a Custom Lookup FIeld on Account Object to Store New Follower

  1. Click Setup.
  2. In the Object Manager, type Account.
  3. Select Fields & Relationships, then click New.
  4. Select Lookup Relationship as Data Type, then click Next.
  5. Select User as Related To, then click Next.
  6. Enter Field Label and click the tab key, the Field Name will populate. 
  7. As a best practice, always input a description. 
  8. Set the Field-level Security for the profiles, make sure to set this field as Visible only. 
  9. Add this field to Page Layout.
  10. Click Save.

Step 2.1: 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 Record-Triggered Flow option, click on Create and configure the flow as follows:
    1. Object: Account
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2.2: Using Decision Element to Check the Custom lookup Field Value is Not Null

Now we will use the Decision element to check if the custom lookup field for User contains any value or not.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.Add_Follower__c}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. When to Execute Outcome: If Only if the record that triggered the flow to run is updated to meet the condition requirements
  6. Click Done.

Step 2.3: Adding a Get Record Element to Find Selected User Follower Status for Current Record

The next step is to use the Get Records element to find the selected user follower status for current record.

  1. On Flow Designer, below the Add Follower is Not Null node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Entity Subscription object from the dropdown list.
  4. Select All Conditions Are Met (AND). 
  5. Set Filter Conditions
    1. Row 1:
      1. Field: ParentId
      2. Operator: Equals
      3. Value:  {!$Record.Id}
    2. Click Add Condition
    3. Row 2:
      1. Field: SubscriberId
      2. Operator: Equals
      3. Value: {!$Record.Add_Follower__c}
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields. 
  8. Click Done.

Step 2.4: Using Decision Element to Check If Selected User is Following the Current Record or Not

Now we will use the Decision element to check the Record Variable from step 2.3 is null or not. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Follower_Status}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 2.5: Create Records – Add users to the Record Follower

To add a new user to Record Follower we need to create a record in the  EntitySubscription object. For this, we will use the Create Records element. Now follow the steps below:

  1. On Flow Designer, below the No node, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. 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 EntitySubscription
    6. Row 1:
      1. Field: ParentId
      2. Value: {!$Record.Id}
    7. Click Add Field
    8. Row 2:
      1. Field: SubscriberId
      2. Value: {!$Record.Add_Follower__c}
  4. Click Done.

In the end, Brenda’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: 57
  5. Interview Label: Add Chatter follower to record {!$Flow.CurrentDateTime}
  6. Click Save. 

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

Proof of Concept

  1. Log in as Brenda David (Profile assigned: – Standard User, Force.com Flow User feature license is not assigned to this user  ).
  2. Navigate to an account record and populate the Add Follower field with Nushi Davoud
  3. Confirm the user has been added
    1. Log out as Brenda.
    2. Switch to Classic
    3. Navigate to the account and review the followers
  4. You are done.

Independent Practice (We-do):

Identify use cases where records on other objects might need to be shared in a more manual way and implement the sharing using the above solution.

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? Feel free to share in the comments below.

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

8 thoughts on “Add Chatter Followers to Record

  1. This seems like it should work but I am getting an error when attempting to set the Add Follower field on the Account. It is preventing me from testing. Any recommendations?

    Flow Details
    Flow Name: Add_Chatter_Followers_To_Record
    Type: Workflow
    Version: 1
    Status: Active
    Flow Interview Details
    Interview Label: Add_Chatter_Followers_To_Record-1_InterviewLabel
    Current User: William Pxxxxx (005410000027fbB)
    Start time: 8/10/2017 3:27 PM
    Duration: 0 seconds
    How the Interview Started
    William Pxxxxx (005410000027fbB) started the flow interview.
    Some of this flow’s variables were set when the interview started.
    myVariable_old = 0014100000jM9lxAAC
    myVariable_current = 0014100000jM9lxAAC
    ASSIGNMENT: myVariable_waitStartTimeAssignment
    {!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
    Result
    {!myVariable_waitStartTimeVariable} = “8/10/2017 3:27 PM”

    1. 1) Use below articles to auto add the members of a public group as chatter followers

      a) http://automationchampion.com/2015/04/18/getting-started-with-process-builder-part-20-add-chatter-followers-to-record/

      b) http://automationchampion.com/2014/06/26/clone-chatter-group-with-members/

      2) Auto Remove Followers From Closed Opportunity :- http://automationchampion.com/2014/06/06/auto-remove-followers-from-closed-opportunity/

      P.S. :- Thank you, it’s the topic of my next article most likely

  2. Would it be possible to use a similar system to unfollow too? I used this way to auto-follow opportunities and it really works great. Now I was just wondering if I can also create the unfollower in the same way???

Leave a Reply

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