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: Read the rest of this entry!
How do you automatically add users into a Chatter Group?
Objectives:
This blog post will help us to understand the following
Create automation associated with creating a new user
Automatically add a user to a specified Chatter group
How to use the quick action in Process Builder
What is a MIXED DML error and how to avoid it?
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.
A few months back, I had written an article Getting Started with Lightning Flow – Part 36 (Automatically Add New Users to a Chatter Group)to discuss a way through which we can auto add a new user toChatter Group. To achieve it, I had usedFlow,Process Builder,andWorkflow Rule. I got excellent feedback, so I wanted to share another way to do achieve the same business use case, using the Process Builderand Global Action.
While this can be solved using various automation tools like Apex or Flow, we will use Process Builder. This is not something that can be accomplished with Workflow Rules.
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 8 steps to solve Brenda’s business requirement using Process Builder. We must:
Create a chatter group
Find the chatter group Id
Creating a custom label to store chatter group Id
Define process properties
Define evaluation criteria
Define process criteria
Set time for actions to execute
Add action – quick actions
Step 1: Create a Chatter Group
Navigate to App Launcherand click on the Groups.
Clicks on theNew 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 Labelbutton.
Enter Short Description the Name will auto-populate.
Now enter the UC Internal Announcement chatter group id in the Value.
Click Save.
Step 4: Define Process Properties
Click Setup.
In the Quick Find box, type Process Builder.
Select Process Builder, then click New.
Name the Process and click the Tab button. The API Name will populate.
As a best practice, always input a description.
The process starts when A record changes.
Click Save.
Step 5: Define Evaluation Criteria
Click on the Add Object node to begin selecting the evaluation criteria.
Select the User object from the dropdown list.
Start the process only when a record is created.
Click Save.
Step 6: Define Process Criteria
Click the Add Criteria node to begin defining the process criteria.
Name the criteria.
The criteria should execute actions when the conditions are met.
Set Conditions
Row 1
Field: User | IsActive
Operator: Equals
Type: Boolean
Value: True
Select All of the conditions are met (AND).
Click Save.
Step 7: set time for actions to execute
When DML operations on certain sObjects sometimes referred to assetup 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).
We are adding time delays to avoid MIXED DML Errors.
Below Scheduled Actions, click Set Schedule.
Set Field Values:
Row 1:
0
Hours
After
CreatedDate
Click Save.
Step 8: Add Action – Quick Actions
Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
For Action Type, select Quick Actions.
Name the action.
Filter Search By: Type
Type: Create a Record
Action: NewGroupMember
Set Quick Action Field Values:
Row 1:
Field: Member ID
Type: Field Reference
Value: User | ID
Click Add Row
Row 2:
Field: Related Record ID
Type: Formula
Value: System Variable | Label | UC_Internal_Chatter_Group_ID
Click Save.
Almost there! Once everything looks good, click the Activate button.
Note:- Before you activate your process, you will want to make sure that you have assigned data in the correct format because Process Builder obeys validation rules. If some fields are required by using validation rules, then make sure you have added those fields. Conversely, if some fields are required on the page layout, you can ignore those fields.
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 AnnouncementChatter group.
Now create a new user via the UI
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:
Check Paused Flow Interviews
Click Setup.
In the Quick Find box, type Paused Flow Interviews.
Now you will see all action waiting for execution.
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.