Allow Anyone to Add or Remove User into Public Group or Queue

Allow Anyone to Add or Remove User into Public Group or Queue

Last Updated on May 31, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How can we use Salesforce Flow to allow anyone to Add or Remove Users from Public Groups or Queues?

In Salesforce, Queues and Public Groups represent a group of users. Only administrators and delegated administrators can create and edit public groups. At the same time, anyone can create and edit their own personal groups. Some of the common question people asked me often are following: 

  • How do we provide an ability to our users so that they can add or remove themself from a Public Group or Queue?
  • Is there a way to make business users delegated Administrator (When we are not using Role) to add or remove anyone into Public Group or Queue?

I have written a few articles on automating Public Group or Queue and automation. Why not check them out while you are at it?! 

  1. Getting Started with Salesforce Flow – Part 53 (Clone a User with their associated Public Group, Queue Membership, and Permission Sets)
  2. Getting Started with Process Builder – Part 19 (Automatically Add New User to Public Group or Queue)
  3. Getting Started with Process Builder – Part 56 (Auto Create a Public Group for new Account)
  4. Getting Started with Process Builder – Part 57 (Automatically add Partner user to Public Group)

Objectives:

After reading this article, you will be able to:

  • Learn about the Group and GroupMember object and how it relates to Public Groups and Queues
  • Create a Screen Flow that will allow users to add or remove users from Public Groups and Queues
  • Understand the component visibility option to create a highly dynamic screen 
  • Use formula to better manage your flow
  • And, last but not the least, discover how to add a Flow to Lightning Record Page and display it to a set of users using Custom Permission 

Business Use Case 

Elise Shelley, a Lead System Administrator at Universal Containers (UC), receives a requirement from his management. They want to develop an application that allows a set of users to add or remove anyone from public groups or queues. 

Automation Champion Approach (I-do):

While this can be solved using various automation tools like Apex, etc, we will use Screen Flow to solve it without using a single line of code. 

Before proceeding ahead, you have to understand the Group object. Groups are sets of users. They can contain individual users, other groups, the users in a particular role or territory, or the users in a particular role or territory plus all the users below that role or territory in the hierarchy.

Field Name Details
Name Name of the group. 
Type Type of the group. One of the following values:

  • Queue
  • Public group

Take a moment to understand GroupMember objects in Salesforce. It represents a User or Group that is a member of a public group.

Field Name Details
GroupId The ID of the Group. 
UserOrGroupId The ID of the User or Group that is direct member of the 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 4 steps to solve Elise’s business requirement using Screen Flow. We must:

  1. Salesforce Flow Steps: Define flow properties 
    1. Create a text variable to store selected public group or queue Id
    2. Add a screen to capture the user’s input
      1. Add a radio buttons to show two options
        • Public Group
        • Queue
      2. Add a radio buttons to show two options
        • Add
        • Remove 
      3. Add a picklist component to display all Public Groups
        1. Add component visibility to show picklist component for public group option (from step 1.2.1.1)
      4. Add a picklist component to display all Queues
        1. Add component visibility to show picklist component for queue option (from step 1.2.1.1)
      5. Add a lookup component to display all Users
    3. Add a Get Records element to find the selected user’s membership status
    4. Add a Decision element to check if the record variable (from step 1.3) and decide the next step 
    5. Add a Create Records element to add a user to public group or queue
    6. Add a Delete Records element to remove a user from public group or queue
    7. Add a Screen element to display the error message in following conditions:
      • When a user is ALREADY a member of a selected group, and you have chosen to Add him to the same group or queue.
      • When a user is NOT a member of a selected group, and you have chosen to REMOVE him from a group or queue.
  2. Create a custom permission 
  3. Assign custom permission to the ReadOnly profile 
  4. Add flow to the lightning home page and add filter criteria

Step 1: Salesforce Flow – 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 Screen Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 1.1: Salesforce Flow – Add a Text Variable to Store Queue or Public Group Id

  1. Under Toolbox, select Manager, then click New Resource to store the selected public group or queue Id 
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varTQueueorGroupId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.2: Salesforce Flow – Add a Screen Element  

  1. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 1.2.1: Salesforce Flow – Add a Radio Buttons Component to Capture the User Selection for Public Group vs Queue

  1. Under Input section on Screen Element. Drag and drop the Radio Buttons component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Data Type: Text
    3. Under Select Choices
      1. Choice 1: Public Group
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: PublicGroup
        4. Choice Label: Public Group
        5. Data Type: Public Group
        6. Choice Value: Add
        7. Click Done.
      2. Add Choice
      3. Choice 2: Queue
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: Queue
        4. Choice Label: Queue
        5. Data Type: Text
        6. Choice Value: Queue
        7. Click Done.
  3. Click Done.

Step 1.2.2: Salesforce Flow – Add a Radio Buttons Component to Capture the User Selection for Add vs Remove 

  1. Under Input section on Screen Element. Drag and drop the Radio Buttons component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Data Type: Text
    3. Under Select Choices
      1. Choice 1: Add
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: Add
        4. Choice Label: Add
        5. Data Type: Text
        6. Choice Value: Add
        7. Click Done.
      2. Add Choice
      3. Choice 2: Remove
        1. Click + New Resource, it will open a pop-up for you
        2. Resource Type: Choice
        3. API Name: Remove
        4. Choice Label: Remove
        5. Data Type: Text
        6. Choice Value: Remove
        7. Click Done.
  3. Click Done.

Step 1.2.3: Salesforce Flow – Add a Picklist Component to Display all Public Groups 

  1. Under Input section on Screen Element. Drag and drop the Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Under Select Choices 
      1. Click + New Resource, it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: selectPublicGroup
      4. Object: Group
      5. Filter Group Records
        1. Row 1:
          1. Field: Type
          2. Operator: Equals 
          3. Value: Regular
      6. Configure Each Choice
        1. Choice Label: Name
        2. Data Type: Text
        3. Choice Value: Id
      7. Store More Group Field values
        1. Field: Id
        2. Value: {!varTQueueOrGroupId}
      8. Click Done
  3. Click Done.

Step 1.2.3.1: Salesforce Flow – Add Component Visibility to Conditionally Display Select Public Group Picklist  

You can control when screen components appear with conditional visibility. In the current scenario, we want to display the Select Public Group Picklist component only when the user has selected the Public Group option in Public Group or Queue radio button (Refer step 1.2.1). 

  1. Under the Picklist Component expand the Set Component Visibility section. 
  2. Now we will define the conditions for when the lookup component is visible.
    1. When to Display Component: Any condition Is Met (OR)
  3. The next step is to define the filter logic if you entered multiple conditions.
    1. Resource: Screen Component >> {!Select_Public_Group}
    2. Operator: Equals
    3. Value: CHOICES >> {!PublicGroup}
    4. Click Done
  4. Click Done.

Step 1.2.4: Salesforce Flow – Add a Picklist Component to Display all Queue

  1. Under Input section on Screen Element. Drag and drop the Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Under Select Choices 
      1. Click + New Resource, it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: selectQueue
      4. Object: Group
      5. Filter Group Records
        1. Row 1:
          1. Field: Type
          2. Operator: Equals 
          3. Value: Queue
      6. Configure Each Choice
        1. Choice Label: Name
        2. Data Type: Text
        3. Choice Value: Id
      7. Store More Group Field values
        1. Field: Id
        2. Value: {!varTQueueOrGroupId}
      8. Click Done
  3. Click Done.

Step 1.2.4.1: Salesforce Flow – Add Component Visibility to Conditionally Display Select Queue Picklist  

You can control when screen components appear with conditional visibility. In the current scenario, we want to display the Select Queue Picklist component only when the user has selected the Queue option in Public Group or Queue radio button (Refer step 1.2.1). 

  1. Under the Picklist Component expand the Set Component Visibility section. 
  2. Now we will define the conditions for when the lookup component is visible.
    1. When to Display Component: All condition Are Met (AND)
  3. The next step is to define the filter logic if you entered multiple conditions.
    1. Resource: Screen Component >> {!Select_Public_Group}
    2. Operator: Equals
    3. Value: CHOICES >> {!Queue}
    4. Click Done
  4. Click Done.

Step 1.2.5: Salesforce Flow – Add a Lookup Component to Display All Users

It’s time to add a Lookup Component to capture the user whom they want to add or remove from public group or queue. For this, we will use the lookup component.

  1. Under Input section on Screen Element. Drag and drop Lookup onto the screen. 
  2. Input the following information:
    1. Enter API Name.
    2. Field API Name: CreatedById (Enter the field API Name that will show up in the list box to represent a record.)
    3. Label: Select User (Enter a label that appears next to the lookup control)
    4. Object API Name: User ( Enter the object API name) 
    5. Required: {!$GlobalConstant.True}
  3. Click Done.

Step 1.3: Salesforce Flow – Adding a Get Record Element to Find Public Group or Queue Membership Status for Selected User 

The next step is to use the Group Member object to check whether the selected user is a member of public group/queue or not.

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the GroupMember object from the dropdown list.
  5. Select Custom Conditions Logic Is Met
    1. Condition Logic: (1 OR 3) AND 2
  6. Set Filter Conditions
    1. Row 1:
      1. Id: GroupId
      2. Operator: Equals
      3. Value: {!Select_Public_Group}
    2. Add Condition
    3. Row 2:
      1. Id: UserOrGroupId
      2. Operator: Equals
      3. Value: {!SelectUser.recordId}
    4. Add Condition
    5. Row 3:
      1. Id: GroupId
      2. Operator: Equals
      3. Value: {!Select_Queue}
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 1.4: Salesforce Flow – Using Decision Element to Check the Record Variable (from step 1.3) and Decide the next Step 

Now we will add a Decision element to decide whether users want to Add or Remove. In the same node we will check the Record Variable from step 1.3 to find if it returns the record or not. Based on that, the Salesforce Flow will create or delete the user from the group or Queue. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label (Add User) the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Selected_User_Membership_Status}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.True}
    2. Add Condition
    3. Row 2:
      1. Resource: {!Add_Or_Remove}
      2. Operator: Equals
      3. Value: {!Add}
  6. Now add second node to decison element.
  7. Under Outcome Details, click on the +
  8. Enter the Label (Remove User) the API Name will auto-populate.
  9. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Selected_User_Membership_Status}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
    2. Add Condition
    3. Row 2:
      1. Resource: {!Add_Or_Remove}
      2. Operator: Equals
      3. Value: {!Remove}
  10. Click Done.

Step 1.5: Salesforce Flow – Create Records – Add a User to Public Group or Queue 

To Add a user to the Public Group or Queue, follow the instructions below:

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: GroupMember
    5. Set Field Values for the Group Member
      1. Row 1:
        1. Field: GroupId
        2. Value: {!varTQueueOrGroupId}
      2. Add Field
      3. Row 2
        1. Field: UserOrGroupId
        2. Value: {!SelectUser.recordId}
  3. Click Done.

Step 1.6: Salesforce Flow – Add a Delete Records Element to Remove a User From Public Group or Queue

To Remove the user from the Public Group or Queue, follow the instructions below:

  1. Drag-and-drop Delete Records element onto the Flow designer. 
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Delete select Use the IDs stored in a record variable or record collection variable.
  4. Select Record(s) to Delete
    1. Record or Record Collection: {!Selected_User_Membership_Status}
  5. Click Done.

Step 1.7: Salesforce Flow – Add a Screen Element to Dispaly Error Message 

Now we have to add a screen element to display the error message for the following conditions:

  • When a user is ALREADY a member of a selected group, and you have chosen to Add him to the same group or queue.
  • When a user is NOT a member of a selected group, and you have chosen to REMOVE him from a group or queue.
  1. Create a Formula forTErrorMessage to dynamically dispaly the error message, as shown in the following screenshot. Always use formula to create a dyanmic and more efficient flow.
  2. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  3. Input the following information:
    1. Enter API Name will auto-populate.
    2. Under Input section on Screen Element. Drag and drop the Display Text component onto the screen. 
    3. Input the following information:
      1. Select formula field {!forTErrorMessage} under Message section.
  4. Click Done

In the end, Elise’s Flow will look like the following screenshot (I turned on Auto-Layout) for this flow:

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. How to Run the Flow: System Context Without Sharing—Access All Data
  5. Type: Screen Flow
  6. API Version for Running the Flow: 52
  7. Interview Label: Add/Remove user into Public Group or Queue {!$Flow.CurrentDateTime}
  8. Click Save.

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

Step 2: Create a Custom Permission 

By using custom permissions, you can grant users access to custom apps. In Salesforce, you can use custom permissions to check which users can access certain functionality. Custom permissions let you define access checks that can be assigned to users via permission sets or profiles – similar to how you assign user permissions and other access settings. You can even use custom permission to bypass the validation rule for certain users or profiles. Let us create custom permission to control flow access to designated users.  

  1. Click Setup.
  2. In the User Interface, type Custom Permissions.
  3. Click on the New button.
  4. Enter Label the Name will auto-populate. 
  5. Click Save.

Feel free to assign custom permission to users via Profile or Permission Set. 

Step 3: Assign Custom Permission to the ReadOnly Profile 

  1. Click Setup.
  2. In the User Interface, type Profiles.
  3. Open the Read Only profile. 
  4. Then navigate to Apps | Custom Permission and click on the Edit button.
  5. Now, assign the Manage Queue PublicGroup custom permission to the profile.
  6. Click Save.

Step 4: Add a Flow to Lightning Home Page and Add Filter Criteria 

The next step is to distribute a flow to Lightning Experience or Salesforce app users by embedding it on a Lightning home page.

  1. Click Setup.
  2. In the Quick Find box, type Lightning App Builder.
  3. Select Lightning App Builder then click on the Edit next to the Home page.
  4. From the Lightning Components pane on the left, drag the Flow component onto the Lightning page canvas.
  5. Input the following information:
    1. Select Add/Remove user into Public Gropu or Queue flow
    2. Layout: Two Columns 
  6. Set Component Visibility
    1. Click + Add Filter
    2. Row 1:
      1. Permissions: Custom Permission > Manage_Queue_PublicGroup
      2. Operator: Equal
      3. Value: True
  7. Click Done.

Once everything looks good, click the Save button. 

Proof of Concept

Now Onwards, a user with the profile ReadOnly can use this application to add remove fusers from public group or queue. 

  1. For this demo, I logged In through a user Sarika Gupta (Profile –ReadOnly). 
  2. Refer video for detailed demo:

Formative Assessment:

I want to hear from you!  

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?  

Make a post and tag me on Twitter @automationchamp using #AutomationChampionFlow.

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

23 thoughts on “Allow Anyone to Add or Remove User into Public Group or Queue

  1. For the users that i want to preform this action….do they need to be granted the manage user permission? “Create, edit, and deactivate users, and manage security settings, including profiles and roles.”

      1. Group member object doesn’t have name field to display all users in selected Public group.If possible when you find solution for this please do let me know. Thanks

      2. As group member doesn’t have name field ,couldn’t able to find the way to show list of users in the selected public group.could you please share the flow which displays users list.Thanks

  2. I by mistake created the public group “XYZ-Test as my company Name” and then I muted it. How I can remove/delete this group.

  3. Hello – Can you please tell me if this would work for users regardless of system permissions? I would like to give access to this Visualforce page via a Permission Set to a user with only basic access (such as Standard User). I tested, but receive “An unhandled fault has occurred in this flow” error. Is there a way to bypass system security in order to make this work for my user?

  4. Thank you for posting these instructions. I have reproduced your flows, visualforce page and tab but I am having an issue with the username field not storing the info or not finding the user. Do you know what could be causing this?

      1. Thanks Rakesh,

        I already figured out my problem. I was using the exact username “test@salesforce.com” instead of their first name/last name

Leave a Reply

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