Add Record to Multiple Chatter Groups – Parsing Multi-Select Picklist fields (Flow)

Add Record to Multiple Chatter Groups – Parsing Multi-Select Picklist fields (Flow)

Last Updated on April 15, 2019 by Rakesh Gupta

In Spring’15 release Salesforce added a new feature on Chatter, that is Add records to Chatter Groups. In the last article Automatically add records to Chatter Group” I had discussed the way to automate this process. In this article, I am going to discuss how you can allow your users to add a record to multiple Chatter Groups and I am also going to discuss a way to parse Multi-Select choice Picklist fields.

Business Use Case

Higher Management in Universal container wants to expand new feature “Add records to Chatter Groups” for their users. Basically, they want a publisher action on Opportunity object that allows their users to add a record to multiple Chatter Groups (Only public Groups).

A solution for the above business requirement

Do you think we have to use Apex code to parse values selected for multi-select choice fields in flow? I think no, this article will help you to understand the way to assign multi-select choice picklist values to a collection variable in a flow or way to parse it.

Design: – when a user clicks on publisher action on Opportunity object it will pop-up a screen, then the user can select multiple Chatter groups, after clicking on Next button it will add Opportunity record to Selected Chatter Groups.

To solve this requirement we will use Visual Workflow, and then we will embed Flow to a Visualforce page to call it from Publisher action. Before proceeding you have to understand  CollaborationGroup and  CollaborationGroupRecord objects in Salesforce.

A. CollaborationGroup:- This object represents a Chatter group.
B. CollaborationGroupRecord:- This object represents the records associated with Chatter groups. CollaborationGroupId represents Id of Chatter Group and RecordId represents ID of the record associated with Chatter Group.

1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
2. Click on New Flow, it will open flow canvas for you. Create two Text type variable VarTOpportunityID (To pass Opportunity ID from Publisher action) and VarTSelected_Chatter_GroupsID we will use it later on this flow.
3. Next step is allowing users to select multiple Chatter Groups. To do that drag-and-drop a Screen Element ( Give the name Select Chatter Groups) onto the window and add a Dynamic choice Multi-Select Picklist field with below detail

Name Data Type Required
Active Chatter Group (Public) Multi-Select Picklist Yes

It will look like the below screenshot

Dynamic choice Multi-select picklist
Dynamic choice Multi-select picklist

Note:- Don’t save the selected Chatter group IDs, because if you assign the results to a variable here, that variable will only store the first value selected.

4. Next step is to assign ID’s of Selected Chatter Group to Text variable {!VarTSelected_Chatter_GroupsID}, to do that Drag-and-drop Assignment Element ( Give the name Chatter Groups IDs to Variable) onto the window and map the field according to the following screenshot

Assign Selected Chatter Group IDs
Assign Selected Chatter Group IDs

5. Next task is to create few Formula fields to calculate the number of chatter groups the user has selected, it’s length, Individual Chatter group ID and for Id’s that remaining to Parse. First, we will create a formula to calculate Lengths of ID’s of Selected Chatter Groups (Length) and Number of Chatter group selected (Counter) as shown in the following screenshot

Formula Fields - Part 1
Formula Fields – Part 1

Now create two formula fields to calculate Parsed ID (Single_Chatter_Group_ID) and Chatter ID’s those are remaining to Parse (Remaining_Chatter_GroupID) as shown in the following screenshot

Formula Fields - Part 2
Formula Fields – Part 2

6. Drag-and-drop a Record Create ( Give the name Add Record to First Chatter Group) onto the window to add a record into chatter groups, if the user has selected only one Chatter group. Please refer to the following screenshot for more details

Add Record to First Chatter Group
Add Record to First Chatter Group

7. Now drag-and-drop Decision element to check counter size. If Counter size < = 1 then leave it as it is, else we have to collect the remaining Chatter groups IDs and then add it to a SObject Collection Variable with recordID (To add records to Chatter Groups, in our case it’s variable {!VarTOpportunityID}. Please refer to the following screenshot for more details

Check the counter size
To check the counter size

8. As we have already added the record to one Chatter Group then we have to TRIM original length (it means remove selected Chatter group ID from variable {!VarTOpportunityID}. Please refer to the following screenshot for more details

Screen Shot 2018-12-11 at 2.19.13 PM

Assign remaining Chatter Groups IDs to Text Variable
Assign remaining Chatter Groups IDs to Text Variable

9. Next step is to add data into a SObject Variable after parsing it. Drag and Drop Assignment Logic (Give the name Add data for single Chatter Group Record) on the window, to assign {!VarTOpportunityID} and formula {!Single_Chatter_Group_ID} into the SObject Variable (CollaborationGroupRecord Object Type) {!Single_Record_Deatils} as shown in the below screenshot

Add details into SObject Variable
Add details into SObject Variable

10. Drag-and-drop Assignment Logic (Give the name All in one) on the window and assign a value from SObject variable {!Single_Record_Deatils} to SObject Collection variable {!All_Record_In_One} (CollaborationGroupRecord Object Type) so at the end of the flow will use it inside the Fast Create to add a record to remaining Chatter Groups. Please refer to the following screenshot for more details

Add SObject Variables into a SObject Collection
Add SObject Variables into a SObject Collection

11. Next step is to check Counter size >= 1.  If counter size is greater than 1 then repeat the process (8-10), else we will use Fast Create element add a record to remaining Chatter Groups. To do that drag-and-drop decision element and check the counter size, as shown in the following screenshot

Check Counter size Greater than 1
Check Counter Size Greater than 1

12. Finally, drag-and-drop Fast Create (Give the name Add record to remaining Chatter Groups) on the window and map the field according to the below screenshot

Add record to remaining Chatter Groups
Add record to remaining Chatter Groups

13. Finally, our Flow will look like the following screenshot

Add Record to multiple Chatter Groups

14. Save the flow with name Add Record to multiple Chatter Group and close the canvas.

It’s time to test this flow

In the next article Call a flow from publisher action I will show you how you can use this flow as Publisher action

1. For time being to test this flow, we will hard code the Opportunity Id into flow variable {!VarTOpportunityID}

Set Default Value to a Variable
Set Default Value to a Variable

2. Click on the Save, button and then click on Run button available on flow canvas. Select as many as Chatter Groups you want, as shown in the following screenshot I have selected 4 Chatter Groups

Selected Chatter Groups
Selected Chatter Groups

Once done Click on Next button.

3. To see the result, open the Opportunity Detail page and navigate to Groups related list

Final Output
Final Output

Note:- In the next article Call a flow from publisher action I will show you how you can use this flow as Publisher action. I will suggest you Implement this first on your developer org test it and then move it to Production.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

21 thoughts on “Add Record to Multiple Chatter Groups – Parsing Multi-Select Picklist fields (Flow)

  1. Hi Rakesh,Thank you for the post.
    Iam getting Too many SOQL queries: 101 error if I choose more than 100 records is there any possibilities to overcome this.

  2. Hi, I am building a similar flow but for some reason I am not able to pass the selected id’s from the dynamic choice to a text variable. Any advice or idea where it could go wrong? (I am using the new Lightning Flow Builder) Thanks!

      1. Hi Rakesh, I checked the data type of my variables. The variable where I want to store my id’s is a text variable. The dynamic choice is a record choice set of data type text where I use the name as label but the id as value.

  3. Hi!
    Thank you for your nice workarround!
    In step 8 you mentioned Formula field “Remove UserChatter Group Id” but i could not find the formula field in your
    post.Could you please provide it?

  4. Hi Rakesh,

    Will mass update in flows hit governor limits? Say for eg, the user selects 10K records to be updated using a flow, will it hit the governor limit of Maximum 10K DML operations per transaction? Please clarify. Thanks.

Leave a Reply

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