Auto Add Chatter Group Members to Public Group!

Auto Add Chatter Group Members to Public Group!

Last Updated on April 17, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How do you automatically add chatter group members to a public group or queue?

Objectives:

After reading this blog, you’ll be able to: 

  • Understand what is a public group 
  • understand mixed DML errors and solutions to avoid such error 
  • Create a public group and queue
  • Work with a public group and queue in flow
  • Add members to public group or queue via flow 
  • and much more

Business Use case

Donna Serdula is working as a System Administrator at Gurukul on Cloud (GoC). She is an experienced Salesforce Administrator and is proficient at using automation to eliminate manual processes. Donna learned that her colleague, Amy Collins, spends several hours per week adding users to a chatter group and then, adding the same users, to a public group:

Amy shares with Donna an example of the business process she follows to add Users to the Sales – EMEA Chatter Group and then to the Sales – EMEA Public Group:

  1. If a user is added to the Sales – EMEA chatter group.
  2. Then, the user must be added to the Sales – EMEA public group. 

Amy mentions to Donna that achieving the above entails tons of manual work as UC has many Chatter and Public Groups and the same business process must be followed in all cases.

Donna assures Amy that she can automate the process going forward! Ah! What a relief! Amy thanks Donna and learns from her how to automate the process. Come along, join Donna and Amy on the journey!

What is a Mixed DML Operation Error?

When DML operations on certain sObjects sometimes referred to as setup objects (such as a User Object), along with, on the non-setup object (such as Accounts), in the same transaction, then, a Mixed DML error is thrown at a User.

The Mixed DML error is generated – when a User performs DML actions on Setup and non-Setup Objects in the same transaction -because some sObjects affect the user’s access to records in the org. Therefore, a user must insert or update these types of sObjects in different transactions to prevent operations from happening with incorrect access-level permissions. For example, a user cannot update an account, and a user role, in a single transaction. However, deleting a DML operation has no restrictions (reference Salesforce help).

Below, I will show you how to use Salesforce Flow to avoid getting a Mixed DML Operation Error.

First, I will perform DML operations on Setup (User) and non-Setup (CollaborationGroupMember) Objects in the same transaction.  This will generate a Mixed DML Operation error because one cannot perform a DML operation on Setup and non-Setup objects in the same transaction.

Next, I will show you how to use a Time-dependent or Scheduled Path, in the Salesforce Flow, to perform DML operations on Setup and non-Setup Objects in the same Process without incurring a Mixed DML operation error. The time-dependent/scheduled action is used because it helps in separating DML operations on Setup and non-Setup objects.

Automation Champion Approach (I-do):

public group comprises many sets of users namely (1) a general set of users; (2) a set of users within a territory; or (3) a set of users within a specific role; or (4) subordinate users within a role hierarchy; or, (5) other groups.  Whereas Public Groups can be used for multiple purposes, Chatter Group is primarily geared toward boosting collaboration among users within an organization. Similar to a public group, a Chatter group comprises a set of users too. Indeed, one can add unlimited users to a Chatter Group.

It is a daily job of a Salesforce Administrator to add users to public groups or chatter groups. In many organizations, it is a System Administrator’s responsibility to keep these groups in sync.

To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Let’s take a pause here, and familiarize ourselves with the CollaborationGroupMember and GroupMember objects in Salesforce.

Object Name Details
CollaborationGroupMember It represents a member of a Chatter Group.
GroupMember It represents a User or Group that is a member of a Public Group.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going 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 Donna’s business requirement using After-Save Record-Triggered Flow. We must:

  1. Create a public group and chatter group 
  2. Salesforce Flow Steps:
    1. Define Flow properties for record-triggered flow
    2. Add a scheduled path
    3. Add a get records element to find the public group
    4. Add a decision element to check if the public group was found or not 
    5. Add a create records element to add chatter group members to a public group 

Step 1: Create a Public Group and a Chatter Group

  1. First of all, create a Chatter group Sales – EMEA
  2. And a Public group Sales – EMEA

Step 2.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 and configure the flow as follows:
    1. Object: Group Membership (CollaborationGroupMember)
    2. Trigger the Flow When: A record is created
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2.2: Salesforce Flow – Add Scheduled Paths

The purpose of using a scheduled path is to execute the flow after 0 hours of CollaborationGroupMember creation. The purpose of putting time-dependent action is to avoid MIXED DML errors.

  1. Under Start, select Add Scheduled Paths (Optional).
  2. Under SCHEDULED PATHS, click on the  New Scheduled Path.
  3. Under Scheduled Path Details, enter the Label the API Name will auto-populate.
  4. Time Source: When CollaborationGroupMember is Created
  5. Offset Number: 0
  6. Offset Options: Hours After
  7. Advanced Options
    1. Batch Size: 200
  8. Click Done.

Step 2.3: Adding a Get Record Element to Find the Public Group (Sales – EMEA)

The next step is to use the Get Records element to find the Sales – EMEA public group. 

  1. On Flow Designer, below the 0 hr After node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Group object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: DeveloperName
      2. Operator: Equals
      3. Value: Sales_EMEA
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

Step 2.4: Using Decision Element to Check If Public Group (Sales – EMEA) was Found or Not 

Now, will use the Decision element to check if the previous Get Records element returns a public group or not. 

  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 the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Public_Group}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 2.5: Add Action – Create a Record

 The next step is to create a record to add chatter group, new members, to a public group, for this, we will use the Create Records element.

  1. On Flow Designer, below the Yes node, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: Group Member
    5. Set Field Values for the Group Member
    6. Row 1:
      1. Field: GroupId
      2. Value: {!Get_Public_Group.Id}
    7. Click Add Field
    8. Row 2:
      1. Field: UserOrGroupId
      2. Value: {!$Record.MemberId}
  4. Click Done.

In the end, Donna’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 Add Chatter Group Members to Public Group! {!$Flow.CurrentDateTime}
  6. Click Save

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

Proof of Concept

  1. Next time, when a user is added to the Chatter Group (Sales EMEA) by the System Administrator.
  2. The flow we created (Using record-triggered flow) will fire and, it will add the user to the Public Group (Sales – EMEA).

Monitor Your Schedule Flow

To monitor Flows that are scheduled, navigate to the following path: 

  1. Navigate to Setup (Gear Icon) | Environments | Monitoring | Time-Based Workflow.
  2. Click Search.
  3. Now look for your Scheduled Flow job displaying information as shown in the following screenshot:
  4. Use the Delete button to delete the time-based Flow job from the queue.

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!

3 thoughts on “Auto Add Chatter Group Members to Public Group!

  1. Great article! One question: What is the reason to add the action in the Process Builder as a Scheduled Action (0 hrs after createdDate) as opposed to an Immediate Action? Does this trick something?

Leave a Reply

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