Getting Started with Process Builder – Part 29 (Auto Remove Followers From Questions With Best Replies)

Getting Started with Process Builder – Part 29 (Auto Remove Followers From Questions With Best Replies)

To understand how to solve a similar business use case using Salesforce Flow. Check out this article Getting Started with Salesforce Flow – Part 37 (Auto Remove Followers From Closed Opportunity).

Big Idea or Enduring Question:

How do you automatically remove followers from Questions with the best replies?

Chatter Answers is a self-service and support community where users can post questions, receive answers and comments from other users, or support agents. Chatter Answers brings together Cases, Questions, Answers, and Knowledge articles in a unified experience.

A few months back, I had written an article Auto follow Question after reply to discuss a way that users can auto-follow questions after reply. In this article, I’m going to discuss a way through which the system will auto-remove the followers from Questions with the best replies. Let’s start with a business use case.

Objectives:

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

  • Launch a flow from Process Builder
  • Automate the removal of followers from Questions with best replies
  • How to use a Decision element to find – record variable or record collection variable contains a record or not
  • How to use a Delete element to delete records

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 Questions with the best replies. They want to develop an automated process that will be responsible for auto-removing followers from Questions with the best replies.

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario, but I’ll use Process Builder and Flow to solve the business requirement. Before proceeding ahead, you have to understand QuestionSubscription objects in Salesforce. 

Before discussing it, 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 Steven’s business requirement using Flow and Process Builder. We must: 

  1. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a record variable to store question record data
    3. Add a get records element to find question follower(s)
    4. Add a decision element to check the id from the record collection variable (from step 1.3)
    5. Add a delete records element to remove the follower(s) from questions
  2. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Add action – flows 

Step 1.1: Lightning Flow – Define Flow Properties 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flows.
  4. Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. Click Done.

Step 1.2: Lightning Flow – Add a Record Variable to Store Question Record Data

  1. Under Toolbox, select Manager, then click New Resource to store Question record.
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varRQuestion
    3. Data Type: Record
    4. Object: Question
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.3: Lightning Flow – Adding a Get Record Element to Find Question Follower(s)

The next step is to find the question 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 Question Subscription object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: QuestioNid
      2. Operator: Equals
      3. Value: {!varRQuestion.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 1.4: Lightning Flow – Using Decision Element to Check the Record Collection Variable (from step 1.3)

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

Step 1.5: Lightning Flow – Add a Delete Records Element to Remove Followers From Questions

  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_Question_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: 50
  5. Interview Label: Remove Followers from Questions Flow {!$Flow.CurrentDateTime}
  6. Click Save

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

Our next task is to create a Process Builder on the Question object to launch a Flow. To create a Process Builder on the Question object, follow the below instructions. 

Step 2.1: Define Process Properties

  1. Click Setup.
  2. In the Quick Find box, type Process Builder.
  3. Select Process Builder, then click New.
  4. Name the Process and click the Tab button. The API Name will populate. 
  5. As a best practice, always input a description
  6. The process starts when A record changes.
  7. Click Save.

Step 2.2: Define Evaluation Criteria

  1. Click on the Add Object node to begin selecting the evaluation criteria.
  2. Select the Question object from the dropdown list.
  3. Start the process when a record is created or edited.
  4. Click Save.

Step 2.3: Define Process Criteria

  1. Click the Add Criteria node to begin defining the process criteria.
  2. Name the criteria.
  3. The criteria should execute actions when the conditions are met.
  4. Set Conditions
    1. Row 1
      1. Field: Quetsion | BestReplyId
      2. Operator:  Is null
      3. Type: Boolean
      4. Value: False
  5. Select All of the conditions are met (AND)
  6. Click Advanced
  7. Click the Yes checkbox – Do you want to execute the actions only when specified changes are made to the record?
  8. Click Save.

The reason why we would select the Yes checkbox for the question — Do you want to execute the actions only when specified changes are made to the record? — is to allow the Process Builder to execute the actions only if the record meets the criteria now, but the values that the record had immediately before it was saved didn’t meet the criteria. This means that these actions won’t be executed when irrelevant changes are made.

Step 2.4: Add Action – Flows

  1. Below Immediate Actions, click Add Action.
  2. For Action Type, select Flows
  3. Name the action.
  4. Select Flow – Remove Followers from Questions Flow
    1. Set Flow variables: 
      1. Row 1
        1. Field: varTQuestion
        2. Type: Field Reference
        3. Value: Select the Question record that started your process
  5. Click Save.

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

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

Proof of Concept

    1. Navigate to the Q&A tab, identify the Question, and click on its title.Chatter Q&A
    2. Currently, the follower count is 2.
    3. Choose one of the replies as the best answer.  Decide which reply is the best answer, and click Choose as Best Answer. As soon as you’re done, refresh the page and check the follower count.Final Outcome
    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!
Preferred Timing(required)

5 thoughts on “Getting Started with Process Builder – Part 29 (Auto Remove Followers From Questions With Best Replies)

Leave a Reply

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

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading