Automatically Add New User to Public Group or Queue

Automatically Add New User to Public Group or Queue

Last Updated on May 22, 2023 by Rakesh Gupta

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 with Flow
  • 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 automatically add new users to the Public Group Universal Container Users.

Automation Champion Approach (I-do):

In the article Automatically Add User to a Chatter Group, we discussed a way to automatically add new users to the Chatter group using clicks, not code. We also discussed a way to avoid MIXED DML errors.

Now let’s take it a step further and discuss a way to auto-add new users to a Queue or Public Group. There are few solutions possible for the above business scenario. We will use Record-Triggered Flow to solve the above business requirement.

Before proceeding ahead, you have to understand group and GroupMember objects. 

  1. Group: – This object represents the Queue and Public Group. They can contain individual users, other groups, and the users in a particular role. By using the 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.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understanding it. Let’s begin building this automation process.

Guided Practice (We-do):

There are two steps to solve Warren’s business requirement using Record-Triggered Flow. We must:

  1. Create a public group
  2. Salesforce Flow Steps:
    1. Define flow properties for record-triggered flow
    2. Formula to determine whether the record is created or updated
    3. Add a decision element to check if the user is Active or Not
    4. Add a get record element to find public group Id 
    5. Add a decision element to check the public group found or not (from step 4)
    6. Add a create records element to add a user to the public group

Step 1: Create a Public Group

  1. Click Setup.
  2. In the Quick Find box, type Public Group.
  3. Click on the Public Group button.
  4. Clicks on the New button. 
  5. Label the Group then press the tab key, the Group Name will auto-populate. 
  6. Click Save.

Step 2.1: Define Flow Properties

  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 Create and configure the flow as follows:
    1. Object: User
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2.2: Formula to Determine Whether the User is Created or Updated

  1. Under Toolbox, select Manager, then click New Resource to determine whether the record is new or old.
  2. Input the following information:
    1. Resource Type: Formula
    2. API Name: forB_IsNew
    3. Data Type: Boolean
    4. Formula: IsNew()
  3. Click Done.

Step 2.3: Using Decision Element to Check if User IsActive or Not

Now we will use the Decision element to check if the user account is active or not.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.IsActive}
      2. Operator: Is Null
      3. Value: {!$GlobalConstant.True}
    2. Add Condition
    3. Row 2
      1. Resource: {!forB_IsNew}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 2.4: Adding a Get Record Element to Find Public Group Id For Universal Container Users

The next step is to find the Public Group for Universal Container Users.

  1. On Flow Designer, below the Yes node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Record Group object from the dropdown list.
  4. Select All Conditions Are Met (AND). 
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: Universal Container Users
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields. 
  8. Click Done.

Step 2.5: Using Decision Element to Check the Public Group from the Record Variable (from step 4)

Now we will use the Decision element to check the Record Variable from step 4 to find if it returns the public group or not.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Find_Public_Group}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
    2. Click Done.

Step 2.6: Add Create Records Element to Add New User to the Public Group

The final step is to add new users to the public group, as soon as the new user account gets activated. We will use the Create Records element. 

  1. On Flow Designer, below the Group Found node, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Input the following information:
    1. How Many Records to Create: One
    2. How to Set the Record Fields: Use separate resources, and literal values
    3. Object: GorupMember
    4. Set Field Values for the Group Member
    5. Row 1:
      1. Row 1:
        1. Field: GroupId
        2. Value: {!Find_Public_Group.Id}
      2. Add Field
      3. Row 2
        1. Field: UserOrGroupId
        2. Value: {!$Record.Id}
  4. Click Done.

In the end, Warren’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: 50
  5. Interview Label: Automatically Add New User to Public Group {!$Flow.CurrentDateTime}
  6. Click Save. 

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

Proof of Concept

Now onwards, when a user account is created, Record-triggered Flow will automatically trigger and add the user to a public group (Universal Container Users). Let’s test it out.

  1. Now create a new user via the UI Create new user
  2. 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? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

12 thoughts on “Automatically Add New User to Public Group or Queue

  1. 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.

  2. 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?

  3. Rakesh, couldn’t you also have set the default value to checked for the onetime checkbox and eliminate the workflow?

  4. 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?

Leave a Reply

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