Getting Started with Process Builder – Part 42 (Auto Remove a Record From Chatter Groups)

Getting Started with Process Builder – Part 42 (Auto Remove a Record From Chatter Groups)

Last Updated on December 3, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

How do you automatically remove records from the Chatter Groups?

Salesforce allows you to add a record to Chatter Groups, which means you can now collaborate and discuss the records as a team in the group. You can only add Account, Contact, Contract, Campaign, Case, Lead, Opportunityand Custom object records to chatter groups. A few months ago, I had written the following articles:

  1. Getting Started with Lightning Flow – Part 26 (Automatically Add a Record to Chatter Group)
  2. Add Record to Multiple Chatter Groups – Parsing Multi-Select Picklist fields (Flow)

Which discuss a way through you can auto-add a record to the Chatter Group. This article goes a step ahead and explains, how to automatically remove the record from  Chatter Groups


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

  • Launch a flow from Process Builder
  • Automate the removal of closed-won opportunities from Chatter Groups
  • 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 from the management to automatically remove the Opportunity record from all chatter groups whenever an opportunity gets updated as closed-won. 

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. We are using Flow as Process builder doesn’t have the ability to delete the records.

Let’s take a pause here, familiar yourself with the CollaborationGroupRecord Object in Salesforce. It represents the records associated with Chatter groups.

Field Name Details
RecordId It represents the Id of the record associated with Chatter Group.
CollaborationGroupId The ID of the Chatter group.

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 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 opportunity record data
    3. Add a get record element to find chatter groups record Ids where opportunity is added 
    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 opportunity from the chatter group 
  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 Opportunity 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: varROpportunity
    3. Data Type: Record
    4. Object: Opportunity
    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 Chatter Groups Record Ids Where Opportunity is Added 

The next step is to find the Chatter Groups Record Ids, in which the opportunity record gets shared or added. To do that follow the below instructions: Add a get records element to find 

  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 Group Record object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: RecordId
      2. Operator: Equals
      3. Value: {!varROpportunity.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 Collection 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_Collaboration_Group_Records}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 1.5: Lightning Flow – Add a Delete Records Element to Remove Opportunity Record From Chatter Groups

The final step is to use the Delete Records element to remove an opportunity from Chatter Groups.

  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_Collaboration_Group_Records}
  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: Auto Remove Record from Chatter Groups {!$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 Opportunity object to launch a Flow. To create a Process Builder on the Opportunity 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 Opportunity 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: Opportunity | StageName
      2. Operator:  Equals
      3. Type: Picklist
      4. Value: Closed Won
  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 – Auto_Remove_Record_from_Chatter_Groups
    1. Set Flow variables: 
      1. Row 1
        1. Field: varTOpportunity
        2. Type: Field Reference
        3. Value: Select the Opportunity 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

Now onwards if a business user updates the Opportunity Stage to Closed Won, Process Builder will automatically remove the record from Chatter Groups.

  1. Below is the current status of Opportunity West Mountain Sign | Q1 2021 in Prospecting Status before the update. Currently, the opportunity is shared with two Chatter groups.
  2. Update the Opportunity to Closed Won
  3. Once you are done, click on the Save button.
  4. Now check the Group related list on the Opportunity object. It’s already removed records from the chatter groups, as shown in the following screenshot:

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!

Leave a Reply

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