Auto Remove a Record From Chatter Groups

Auto Remove a Record From Chatter Groups

Last Updated on May 22, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How do you automatically remove a record 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 groupYou 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. Automatically Add a Record to Chatter Group
  2. Hurray! Parsing a Multi-Select Picklist is Trouble No More! Phew! 

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 Group

Objectives:

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

  • Avoid hard code of Id using the get records element 
  • Use decision element to check record values
  • Create a record-triggered flow to auto-remove record from chatter groups
  • and much more

Business Use case

Steven Greene is working as a System Administrator at Gurukul on Cloud (GoC). He has received a new requirement from the management; once an opportunity is marked as closed, automatically remove it from all chatter groups. 

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario, but I’ll use After-save Record-Triggered Flow to solve the business requirement. 

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 5 steps to solve Steven’s business requirement using Record-triggered Flow. We must:

  1. Define flow properties for record-triggered flow
  2. Add a decision element to check if opportunity is closed or not
  3. Add a get record element to find chatter groups record where opportunity is added 
  4. Add a decision element to check if opportunity is added to chatter groups or not (from step 4) 
  5. Add a delete record element to remove the opportunity from the chatter groups 

Step 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 
    1. Object: Opportunity
    2. Trigger Opportunity 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: Using Decision Element to Check if Opportunity is Closed or Not

Now we will use the Decision element to check the isClosed to ensure that it is equal to True. 
 
  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 theLabel theAPI Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.IsClosed}
      2. Operator: Equals 
      3. Value: {!$GlobalConstant.True}

Step 3: 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. On Flow Designer, below the Closed node, click on the +icon and select the Get Element element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Group Record object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: RecordId
      2. Operator: Equals
      3. Value: {!$Record.id}
  6. How Many Records to Store:
    1. select All records
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

Step 4: Using Decision Element to Check the Record Collection Variable (from step 4)

Now we will use the Decision element to check the Record Collection Variable from step 3 to find if it returns the collaboration group records for the current record or not. 

  1. On Flow Designer, click on the +icon and select the Decision 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: {!Get_Collaboration_Group_Records}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 5: 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. On Flow Designer, click on the +icon and select the Delete Records element.
  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: {!Get_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: 55
  5. Interview Label: Auto Remove Record from Chatter Groups {!$Flow.CurrentDateTime}
  6. Click Save

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, record-triggered after-save 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? 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!

Leave a Reply

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