Last Updated on January 26, 2021 by Rakesh Gupta

Advertisement

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

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

Before proceeding ahead, you have to understand the 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.

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 lookup component to display all Users
          Add component visibility to show lookup component for add follower option (from step 1.1.1)
      2. Add a picklist component to display the account followers
          Add component visibility to show picklist component for remove follower option (from step 1.1.1)
    3. Add a Decision element to check if a 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.3) 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 flow to the lightning home page and add filter criteria

Step 1: Salesforce Flow – Define Flow Properties

  1. Select the Screen Flowoption and click on Next and configure the flow as follows:
  2. It will open the flow designer for you.

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

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

Step 1.2: Salesforce Flow – Add a Screen Element

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

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 picklist component.

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.

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

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.

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.

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.

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 to find if it returns the record or not. step 1.4

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.

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

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

Once everything looks good, perform the steps below:

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

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

Step 3: Add a Flow 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. Select click on the Lightning Record Pages, Label to open the page.
  2. Click on the Edit button to o pen a Lightning page in the Lightning App Builder.
  3. Make sure to enable the Dynamic Action for Account.
  4. From the Highlights Panel
    1. C lick Add Action
    2. In the Actions modal, choose an action i.e. Add/Remove Follower, as shown in the following screenshot:
  5. Set Filter Conditions
  6. Row 1:
    1. Field: Record > Account Owner > Role > Developer Name
    2. Operator: Equal
    3. Value: DirectorDirectSales
  7. Once everything looks good, click the Save button.

Proof of Concept

Now Onwards, a user with the role of

  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 button and perform the steps, as shown in the video:Add/Remove Follower
  3. T he 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.

Please click here to read the original article as posted on Automation Champion.

We source the web to bring you best Salesforce articles for our reader’s convenience. If you want to have this article removed, please follow guidelines at Digital Millennium Copyright Act (DMCA)..