In this article Automatically Add New User to Chatter Group, We had discussed a way to auto add new users to Chatter group using click not code. We also discussed a way to avoid MIXED DML error. In this article, we are going to discuss a way to auto add new users to Queue or Public Group. Let’s start with a business use case
Business Use case
Warren Mason is working as System administrator at Universal Containers (UC). His organization wants to develop an application to auto add new users to Public Group “Universal Container Users.”
Solution for the above business requirement
There are few solutions possible for the above business scenario. We will use Flow, Workflow Rule and Process Builder to solve the above business requirement. Before proceeding ahead, you have to understand Group and GroupMember objects.
- Group: – This object represents Queue and Public Group both. Groups are sets of users. They can contain individual users, other groups, the users in a particular role. By using Type field, you can distinguish between Queue and Public Group. For Public Group (Use Type = Regular) and for Queue (Use Type = Queue).
- GroupMember: – Represents a User or Group that is a member of a public group.
Follow the below instructions to create a Flow, Workflow Rule and Process Builder to solve the above business requirement
1. Create a Custom field OneTimeActivity (Data Type :- Check-box, Default Value:- False) on the User object. We will use this in Process Builder.
2. To create a Flow, click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
3. Click on New Flow, it will open Flow canvas for you. Now we have to create a few variables. First create a Text variable VarT_UserId to store the user Id (we will pass new user Id through Process Builder) as shown in the below screenshot
Second Variable VarT_PublicGroupId is used to store public Group Id. In this scenario public group Universal Container Users Id, as shown in the following screenshot
4. To add a new user to Public Group, drag and drop a Record Create ( Give the name Add user to Public Group) onto the window and map the fields according to below details
- Select Object GroupMember
- Enter Assignment GroupId= {!VarT_PublicGroupId} and UserOrGroupId= {!VarT_UserId}, as shown in the below screenshot
5. Finally, your Flow will look like the following screenshot
6. Save your flow with name Automatically add new user to public group and close the canvas. Don’t forget to Activate the Flow.
Launch a Flow from Process Builder
Our next task is to create a workflow on User object to update the OneTimeActivity field to True then we will create a Process on User object to launch a Flow. To create a workflow on the User object follow the below instructions
1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | New Rule, then select object User from the drop-down
2. Enter Name, for Evaluate the rule when a record is select Created, For Rule Criteria select is Active To True, as shown in the below screenshot
3. Now Add a time trigger to to update OneTimeActivity To True (Custom field – Checkbox ) after 0 hours of record Created date. To do this click on Add Time Trigger button and Set the length after how many days/hours workflow will fire i.e. in hours and days, I’ve selected 0 hours after the Created Date. Now add one field update action for time dependent workflow and update the OneTimeActivity to True. You can take help from the following screenshot
4. Save the workflow rule and activate it.
5. Our next task is to create a Process on User object to launch a Flow. To create a Process click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder and click on the New button, Enter Name, API Name and then click on the Save button
6. Click on Add Object, select User object and for the entry criteria, Select when a record is created or edited, as shown in the below screenshot and once you are done click on the Save button
7. The next task is to add Process Criteria, To do this click on Add Criteria, enter Name, Type of action and set filter conditions (In this case set [User].OneTimeActivity__c Equals True) and click on the Save button, as shown in the following screenshot
8. The next step is to add an Immediate action to Process. Click on Add Action (Under Immediate actions), Select the type of action to create (In our case Flows) , and then fill out the fields to define the action, as shown in the following screenshot
9. Final Step is to add one more Immediate action to update OneTimeActivity to False, We will use update Records action in the Process, Please refer to the following screenshot for more details
10. Once you are done, click on the Save button, it will redirect you to Process canvas. Finally the Process will look like the following screenshot
Don’t forget to active the Process by clicking on the Activate button.
It’s time to test this App
To test this application follow the below instructions
1) Navigate to Name | Setup | Administration Setup | Manage Users | Users
2) Create a New User
3) Now navigate to the Public Group (Universal Container Users) and check new user under View all users list
Note: – I will suggest you to implement this first on your developer org test it and then move it to Production.
12 thoughts on “Getting Started with Process Builder – Part 19 (Automatically Add New User to Public Group or Queue)”
Nityanand Wachche
Storing hardcoded id of public group (VarT_PublicGroupId ) is not good practice.Because Id will keep on changing environment to environment.Is there any alternative solution for this situation ?
Thanks for the reply.
Rakesh Gupta
Use Custom Label https://automationchampion.com/2017/04/04/getting-started-with-process-builder-part-60-just-say-no-to-hard-coded-id/
Carolyn Price
Great article! I used a fairly similar method, outline here: https://taroworks.zendesk.com/hc/en-us/articles/208904966-Can-I-automate-Public-Group-membership-based-on-a-field-on-the-user-record-
Question: Why can’t you reference the Profile in the Process Builder logic? I tested it first using the Profile Id (however, it didn’t work), but the Process Builder + Flow works when you use a picklist instead.
Thanks!
Carolyn
Rakesh Gupta
I am sorry, I am not able to understand your question.
Steve
What about the existing Users? I want to add existing users to public group, how can I do that? Do I need to update the user last modified date, so that the process builder gets called or is there any other way?
Rakesh Gupta
You are right, or you use can Data Loader
Victor
Rakesh, couldn’t you also have set the default value to checked for the onetime checkbox and eliminate the workflow?
Rakesh Gupta
I think no.
Jim
Nice article, But I Wonder Why YOU Use A Time Based workflow to update the onetime checkbox? Does this break it to a separate transaction?
Rakesh Gupta
To avoid MIXED DML error
Jim Kaskade
Great article.
Rakesh Gupta
Thank you 🙂