Process Builder: Automatically Add New User to Public Group or Queue



In this article Automatically Add New User to Chatter Group, We had discussed a way to auto add new users toChatter 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 in Universal Container. His organization wants to develop an application to auto add new users to Public Group “Universal Container Users“.
Solution of above business requirement
There are few solutions possible for the above business scenarioWe will use Flow, Workflow Rule and Process Builder to solve the above business requirement. Before proceeding ahead, you have to understand Group andGroupMember objects. 
  1. 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).
  2. 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

6Save your flow with name Automatically add new user to public group and close the canvas. Don’t forget toActivate 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 updateaction 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 NameAPI 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 NameType 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.

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget