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!
Posted at 2:26 AM by Rakesh Gupta, on April 16, 2015
Big Idea or Enduring Question:
How do you automatically add new users to a Public Group or Queue?
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 Public Group or Queue
How to use flows action in Process Builder
What is MIXED DML error and how to avoid it
Business Use case
Warren Mason is working as a System administrator at Universal Containers (UC). His organization wants to develop an automation to auto add new users to Public Group Universal Container Users.
Now let’s take it a step further and discuss a way to auto add new users to Queue or Public Group. There are few solutions possible for the above business scenario. We will use Flow and Process Builder to solve the above business requirement.
Before proceeding ahead, you have to understandGroup and GroupMember objects.
Group: –This object represents the QueueandPublic Group. They can contain individual users, other groups, the users in a particular role. By using theType field, you can distinguish betweenQueueandPublic Group. ForPublic Group(UseType = Regular) and forQueue(UseType = Queue).
GroupMember: – 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 to go through the following Flow diagram and understand it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 5 steps to solve Warren’s business requirement using Flow and Process Builder. We must:
Create a public group
Find the public group Id
Creating a custom label to store public group Id
Lightning Flow Steps:
Define flow properties for auto-launched flow
Add a text variable to store user-id
Add a create records element to add users to the public group
Process Builder Steps:
Define process properties
Define evaluation criteria
Define process criteria
Set time for actions to execute
Add action – flows
Step 1: Create a Public Group
Click Setup.
In the Quick Find box, type Public Group.
Click on the Public Group button.
Clicks on theNew button.
Label the Group then press the tab key, the Group Name will auto-populate.
Click Save.
Step 2: Find the Public Group Id for UC Internal Announcements
The next step is to find out the Id of the public group Universal Containers Users. 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 group where (name=’Universal Container Users’ and Type = ‘Regular’)
Make sure to copy the Id.
Step 3: Creating a Custom Label to Store Public Group Id
Click Setup.
In the Quick Find box, type Custom Labels.
Select Custom Label then click on the New Custom Labelbutton.
Enter Short Description the Name will auto-populate.
Now enter the Universal Containers Users public group id in the Value.
Click Save.
Step 4.1: Lightning Flow – Define Flow Properties
Click Setup.
In the Quick Find box, type Flows.
Select Flows then click on the New Flow.
Select the Autolaunched Flow (No Trigger) option and click on Nextand configure the flow as follows:
How do you want to start building: Freeform
Click Done.
Step 4.2: Lightning Flow – Add a Text Variable to Store User Id
Under Toolbox, select Manager, then click New Resource to pass the store User Id.
Input the following information:
ResourceType: Variable
API Name: varTUserId
Data Type: Text
Default Value: {!$GlobalConstant.EmptyString}
Check Available for Input
Check Available for Output
Click Done.
Step 4.3: Lightning Flow – Create Records – Add users to the Public Group
To add a new user toPublic Group drag and drop aRecord Create onto the flow designer and map the fields according to the below details.
Under Toolbox, select Elements. Drag and drop Create Records onto the canvas.
Input the following information:
EnterLabel theAPI Name will auto-populate.
How Many Records to Create: One
How to Set the Record Fields: Use separate resources, and literal values
Object: Group Member
Set Field Values for the Group Member
Row 1:
Field: GroupId
Value: {!$Label.UC_Public_Group_Id}
Click Add Row
Row 2:
Field: UserorGroupId
Value: {!varTUserId}
Click Done.
In the end, Warren’sFlowwill look like the following screenshot:
Once everything looks good, perform the steps below:
Click Save.
Enter Flow Label theAPI Name will auto-populate.
Click Show Advanced.
API Version for Running the Flow: 50
Interview Label: Automatically Add New User to Public Group {!$Flow.CurrentDateTime}
Click Save.
Almost there! Once everything looks good, click the Activate button.
Our next task is to create a Process on theUser object to launch a Flow, only when a user is created.
Step 5.1: 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.2: 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 5.3: 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: equal
Type: Boolean
Value: True
Select All of the conditions are met (AND).
Click Save.
Step 5.4: set time for actions to execute
DML operations on certain sObjects 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 5.5: Add Action – Flows
Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
For Action Type, select Flows.
Name the action.
Select Flow – Automatically Add New User to Public Group.
Set Flow variables:
Row 1
Field: varTUserId
Type: Field Reference
Value: User | Id
Click Save.
In the end, Warren’s Processwill look like the following screenshot:
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Now onwards, when a user account is created, Process Builder will automatically trigger and launch the Flow. It will then add the user to a public group (Universal Container Users) post after a few minutes. Let’s test it out.
Now create a new user via the UI
Once the user is created, they are automatically added to the public group Universal Container Users within a few seconds, 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.