Getting Started with Salesforce Flow – Part 36 (Automatically Add a New Users to a Chatter Group)

Getting Started with Salesforce Flow – Part 36 (Automatically Add a New Users to a Chatter Group)

Last Updated on January 4, 2021 by Rakesh Gupta

To understand how to solve the same business use case using Process Builder. Check out this article Getting Started with Process Builder – Part 24 (Automatically Add User to a Chatter Group).

Big Idea or Enduring Question:

How do you automatically add users into a Chatter Group? 

Objectives:

This blog post will help us to understand the following

  • Use After-save Record-Triggered Flow add users to a chatter group
  • Add a Time-dependent action in After-save Record-Triggered Flow
  • What is a MIXED DML error and how to avoid it?
  • Monitor Time-based flow queue

Business Use case

Brenda David is working as a System administrator at Universal Containers (UC). Her next assignment is to create a process to auto add a new user to Chatter Group (UC Internal Announcements).

Automation Champion Approach (I-do):

The process of creating a new user can involve many steps that have to be repeated for each person. This can become time-consuming for admins. However, this process can be made easier with automation.

While this can be solved using various automation tools like Apex or Process Builder, we will use After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Before proceeding, ahead, understanding CollaborationGroupMember objects in Salesforce. It represents a member of a Chatter group.

Field Name Details
CollaborationGroupId Represent Id of the Chatter Group
MemberId Represent Id of the User (Group member)

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 Brenda’s business requirement using After-save Record-Triggered Flow. We must:

  1. Create a chatter group
  2. Find the chatter group Id
  3. Creating a custom label to store chatter group Id
  4. Salesforce Flow
    1. Define flow properties for record-triggered flow
    2. Add a scheduled path
    3. Add a create records element to add a new user to a Chatter group 

Step 1: Create a Chatter Group

  1. Navigate to App Launcher and click on the Groups.
  2. Clicks on the New button. 
  3. Name the Group and make sure to select the Private Access Type.
  4. 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. 

  1. Click Setup | Developer Console 
  2. In the Query Editor, run the following SOQL query 
    1. Select id, name from collaborationgroup where (name=’UC Internal Announcements’)
  3. Make sure to copy the Id. 

Step 3: Creating a Custom Label to Store Chatter Group Id

  1. Click Setup.
  2. In the User Interface, type Custom Labels.
  3. Click on the New Custom Label button.
  4. Enter Short Description the Name will auto-populate. 
  5. Now enter the UC Internal Announcement chatter group id in the Value.
  6. Click Save.

Step 4.1: Salesforce Flow – Define Flow Properties 

As we have a requirement of creating a record in (CollaborationGroupMember) when a user is created. This is why we have to use the After-save flow on Opportunity.

  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 and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Trigger the Flow When: A record is created
    3. Run Flow: After the record is saved
    4. Object: User
  5. Select All Condition Are Met (AND)
  6. Set Conditions
    1. Row 1
      1. Field: User | IsActive
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  7. Click Done.

Step 4.2: Salesforce Flow – Add Scheduled Paths

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, CollaborationGroupMember), 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).

That’s why we are going to add a time delays 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: User: Created Date
  5. Offset Number: 0
  6. Offset Options: Hours After
  7. Click Done.

Step 4.3: Salesforce Flow – Create Records – Add New User to Chatter Group ‘UC Internal Announcements’ 

The next step is to add new users to the chatter group. We will use the Create Records element. 

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. 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: CollaborationGroupMember
    5. Set Field Values for the Group Member 
    6. Row 1:
      1. Row 1:
        1. Field: CollaborationGroupId
        2. Value: {!$Label.UC_Internal_Chatter_Group_ID}
      2. Add Field
      3. Row 2
        1. Field: MemberId
        2. Value: {!$Record.Id}
  3. Click Done.

In the end, Brenda’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: 51
  5. Interview Label: Add User to a Chatter Group {!$Flow.CurrentDateTime}
  6. Click Save

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

Proof of Concept

Now onwards, if a system administrator creates a new user, then Process Builder will automatically trigger and add the user to the UC Internal Announcement Chatter group.

  1. Now create a new user via the UI
  2. Once the user is created, they are automatically added to the chatter group UC Internal Announcements within a few seconds, as shown in the following screenshot:

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. Now look for your Scheduled Flow job displaying information as shown in the following screenshot:

  3. Use the Delete button to delete the time-based Flow job from the queue.

Independent Practice (You-do):

Automatically add a user to a different user group based on their role or profile. 

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!

92 thoughts on “Getting Started with Salesforce Flow – Part 36 (Automatically Add a New Users to a Chatter Group)

  1. Hi Rakesh,

    In immediate workflow action. I don’t see Flow trigger option. Sorry i am new to flow. May be i am asking silly question.

  2. Trying to test this using the Process Builder and getting the following error: Workflow Action Failed to Trigger Flow
    The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301290000004RIe. Contact your administrator for help.

    For some reason the process won’t start because of the Flow. Any ideas?

Leave a Reply

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