Last Updated on May 19, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
How do you automatically add a record to the Chatter Group?
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, Opportunity, and Custom object records to chatter groups.
Objectives:
After reading this article, the reader will be able to:
- Use After-save Record-Triggered Flow to add the newly created opportunities to chatter Group
- How to refer custom label in After-save Record-Triggered Flow
- Use a Decision element to find – record variable or record collection variable contains a record or not
Business Use case
Steven Greene is working as a System Administrator at Universal Containers (UC). He has received a new requirement from the management, whenever an Opportunity is created or updated with an amount greater than $ 100,000, then automatically it to Chatter Group (UC Internal Announcements).
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 4 steps to solve Steven’s business requirement using Salesforce Flow. We must:
- Create a chatter group
- Find the chatter group Id
- Creating a custom label to store chatter group Id
- Salesforce Flow Steps:
- Define flow properties for record-triggered flow and check the amount
- Add a get record element to find collaboration group record Id for the current opportunity
- Add a decision element to check the collaboration group id from the record variable (from step 4.2)
- Add a create records element to add opportunity record to chatter group
Step 1: Create a Chatter Group
- Navigate to App Launcher and click on the Groups.
- Clicks on the New button.
- Name the Group and make sure to select the Private Access Type.
- Click Save.
Step 2: Find the Chatter Group Id for UC Internal Announcements
The next step is to find out the Id of the chatter group UC Internal Announcements. One possible workaround is to use the Developer Console.
- Click Setup | Developer Console
- In the Query Editor, run the following SOQL query
- Select id, name from collaborationgroup where (name=’UC Internal Announcements’)
- Make sure to copy the Id.
Step 3: Creating a Custom Label to Store Chatter Group Id
- Click Setup.
- In the User Interface, type Custom Labels.
- Click on the New Custom Label button.
- Enter Short Description the Name will auto-populate.
- Now enter the UC Internal Announcement chatter group id in the Value.
- Click Save.
Step 4.1: Salesforce Flow – Define Flow Properties
As we have a requirement of creating a record in (CollaborationGroupRecord), this is why we have to use After Save flow.
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Trigger the Flow When: A record is created or updated
- Run Flow: After the record is saved
- Object: Opportunity
- Select All Condition Are Met (AND).
- Set Conditions
- Row 1
- Field: Opportunity | Amount
- Operator: Greater Than
- Value: 100000
- Row 1
- Select Only when a record is updated to meet the condition requirements.
- Click Done.
Step 4.2: Salesforce Flow – Adding a Get Record Element to Find Collaboration Group Record Id For the Current Opportunity
The next step is to find the Collaboration Group Record Id For the current opportunity, to make sure that – opportunity is not already added to the group. To do that follow the below instructions:
- Under Toolbox, select Element.
- Drag-and-drop Get Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Record CollaborationGroupRecord object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: CollaborationGroupId
- Operator: Equals
- Value: {!$Label.UC_Internal_Chatter_Group_ID}
- Add Condition
- Row 2:
- Field: RecordId
- Operator: Equals
- Value: {!$Record.Id}
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 4.3: Salesforce Flow – Using Decision Element to Check the Record Id from the Record Variable (from step 4.2)
Now we will use the Decision element to check the Record Variable from step 4.2 to find if it returns the record id or not.
- Under Toolbox, select Element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Find_Collaboration_Group_Record_Id.Id}
- Operator: Is Null
- Value: {!$GlobalConstant.True}
- Row 1:
- Click Done.
Step 4.4: Salesforce Flow – Create Records – Add Opportunity Record to Chatter Group
The next step is to add an opportunity record to the chatter group. We will use the Create Records element.
- Under Toolbox, select Elements. Drag and drop Create Records onto the canvas.
- Input the following information:
- Enter Label the API Name will auto-populate.
- How Many Records to Create: One
- How to Set the Record Fields: Use separate resources, and literal values
- Object: CollaborationGroupRecord
- Set Field Values for the Group Record
- Row 1:
- Row 1:
- Field: CollaborationGroupId
- Value: {!$Label.UC_Internal_Chatter_Group_ID}
- Add Field
- Row 2
- Field: RecordId
- Value: {!$Record.Id}
- Row 1:
- Click Done.
In the end, Steven’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- Type: Record-Triggered Flow
- API Version for Running the Flow: 50
- Interview Label: Add Permission Set to New Users {!$Flow.CurrentDateTime}
- 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, Salesforce Flow will automatically add the record from Chatter Groups.
- Below is the current amount of Opportunity West Mountain Sign | Q1 2021 is 1,200 USD Status before. Currently, the opportunity is not shared with any Chatter groups.
- Update the Amount to $1.1 M.
- Once you are done, click on the Save button.
- Now check the Group related list on the Opportunity object. Record is already added to chatter group UC Internal Announcements, 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.
Do you know if we can also include notification to group members when this happens? We haven’t seen a way to do it other than post a separate message to the feed which seems slightly redundant.
It’s possible but in some scenario it may hit the governor limits. So best approach is to post a separate message to the feed.
Good example of using flow
Awesome. Thanks
When opportunity add products that amount reflected to contract object amount field , using flow + process builder,how to do this please give suggestion on this any one.(urgent)
You mean to say summation of Opportunity Products amount to Contract Amount field ?
yes.