Getting Started with Salesforce Flow – Part 61 (Clone a Public Group or Queue with Members)

Getting Started with Salesforce Flow – Part 61 (Clone a Public Group or Queue with Members)

Last Updated on June 14, 2021 by Rakesh Gupta

Big Idea or Enduring Question:

How do you provide a way to clone a public group or queue with members to your users or system administrators? 

In this article Clone a Chatter Group with Members, I had discussed a way through which you can provide a wizard to your users to clone Chatter group with members. This article will show you how you can provide a wizard to clone public group or queue with members to your users or system administrators.

Before going ahead I want to say big thanks to Mr. Mark Ross to feature my idea in his #Sp14FlowHackathon article.

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)
  5. Getting Started with Salesforce Flow – Part 60 (Allow Anyone to Add or Remove User into Public Group or Queue)

Objectives:

This blog post will help us to understand the following

  • Use a Screen a flow to take the user input to create a Public Group or Queue
  • Learn how to work with the picklist component (Screen Flow)
  • Learn how to use a Decision element to find whether a Record variable or a Record collection variable contains a record
  • Learn how to associate queue with supported objects through Flow
  • Find out how to use the Loop element to extract records from a record collection variable.
  • And, last but not least, discover how to use the Create Records element to create multiple records (add a user to a new public group or queue) at once (Bulk Safe)

Business Use Case

Brenda David is working as a System administrator at Universal Containers (UC). She has received a requirement from the management to create a wizard that allows a set of users to create a Public Group or Queue with members by cloning them quickly.

Automation Champion Approach (I-do):

While this can be solved using various tools:
  1. Lightning Web Component 
  2. Apex Code
  3. Data Loader
  4. AppExchange App
We will use Salesforce Flow to solve it. 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. 
Take a moment to understand QueueSobject objects in Salesforce. It represents the mapping between a queue Group and the sObject types associated with the queue, including custom objects.
Field Name Details
QueueId The ID of the Queue. 
SobjectType A list of object types that can be associated with the queue specified by the QueueId.
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 understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 4 steps to solve Brenda’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 picklist component to display all Public Groups
        1. Add component visibility to show picklist component for public group option 
      3. Add a picklist component to display all Queues
        1. Add component visibility to show picklist component for queue option
      4. Add a Text field to capture Group or Queue Name
      5. Create a formula to construct a Unique name for a group or queue (by removing spaces) 
    3. Add a Get Records element to find existing public group or queue
    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 create a new public group or queue
    6. Add a Decision element to check if user has been selected to clone Public groups and Queue 
      1. Add a Get record element to find the existing queue supported QueueSobject
      2. Add a Loop element to retrieve records from the record collection variable (from step 1.6.1) 
      3. Add an Assignment element to Assign the newly created queue id to the loop variable 
      4. Add an Assignment element to add the Record variable to a Record collection variable
      5. Add a Create records element to add supported objects to newly created queues
    7. Add a Get Records element to find the members of existing public Group or Queue
    8. Add a Decision element to check the Record collection variable (from step 1.7)
    9. Add a Loop element to extract Ids from the Record collection variable (from step 1.7)
    10. Add an Assignment element to Assign the new groupid to the loop variable 
    11. Add an Assignment element to add the Record variable to a Record collection variable
    12. Add a Create Records element to add members to the newly created public 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 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.2.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: 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_or_Queue}
    2. Operator: Equals
    3. Value: CHOICES >> {!PublicGroup}
    4. Click Done
  4. Click Done.

Step 1.2.3: 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.3.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_or_Queue}
    2. Operator: Equals
    3. Value: CHOICES >> {!Queue}
    4. Click Done
  4. Click Done.

Step 1.2.4: Salesforce Flow – Add a Text Component to Store Group or Queue Name

  1. Under Input section on Screen Element. Drag and drop the Text component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Select Require checkbox.
  3. Click Done.

Step 1.2.5: Salesforce Flow – Create a Formula to Construct Unique Name for Group or Queue

  1. Under Toolbox, select Managerthen click New Resource to create a formula to calculate elapsed days since the last password changed.
  2. Input the following information
    1. Resource Type: Formula
    2. API Name: forTAPIName
    3. Data Type: Text
    4. Formula: SUBSTITUTE({!Group_or_Queue_Name}, ” “, “”)
  3. Click Done.

Step 1.3: Salesforce Flow – Adding a Get Record Element to Find the Existing Public Group or Queue

The next step is to use the Group object to find the members of an existing public group or queue. For this will use the Get Records element. 

  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 Group object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Id: {!varTQueueOrGroupId}
  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)

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

  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 the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Public_Group_or_Queue}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 1.5: Salesforce Flow – Create Records -Element to create a New Public Group or Queue 

The next step is to create a new public group or queue. For this will use the Create Records element. 

  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: Group 
    5. Set Field Values for the User
      1. Row 1:
        1. Field: DeveloperName
        2. Value: {!forTAPIName}
      2. Add Field
      3. Row 2
        1. Field: DoesIncludeBosses
        2. Value: {!Get_Public_Group_or_Queue.DoesIncludeBosses}
      4. Add Field
      5. Row 3
        1. Field: DoesSendEmailToMembers
        2. Value: {!Get_Public_Group_or_Queue.DoesSendEmailToMembers}
      6. Add Field
      7. Row 4
        1. Field: Name
        2. Value: {!Group_or_Queue_Name}
      8. Add Field
      9. Row 5
        1. Field: Type
        2. Value: {!Get_Public_Group_or_Queue.Type}
  3. Click Done.

Step 1.6: Salesforce Flow – Using Decision Element to Check if a User has been Selected to Clone Public Group or Queue 

Now we will use the Decision element to check if the system administrator (or any user) who is cloning the queue has been selected to clone Public group and 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 (Clone Queue) the API Name will auto-populate.
    1. Update the Default Outcome, enter the Label to Clone Group.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Public_Group_Or_Queue}
      2. Operator: Equals
      3. Value: {!Queue}
  6. Click Done.

Step 1.6.1: Lightning Flow – Adding a Get Record Element to Find the Existing Queue Supported QueueSobject 

The next step is to use the Get Records element to find the existing queue supported QueueSobject.  

  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 Queue sObject object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: QueueId
      2. Operator: Equals
      3. Value: {!varTQueueOrGroupId}
  7. How Many Records to Store:
    1. select All records
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 1.6.2: Salesforce Flow –  Add a Loop Element to Retrieve Records from Record Collection Variable (from step 1.6.1) 

  1. Drag-and-drop the Loop element onto the Flow designer. 
  2. Enter a name in the Label (Loop Through Supported Objects) field – the API Name will auto-populate.
  3. For Collection Variable select {!Get_Supported_Object}.
  4. For Specify Direction for Iterating Over Collection select the option First item to last item.
  5. Click Done.

Step 1.6.3: Salesforce Flow – Adding an Assignment Element to Assign the Newly Created QueueId to the Loop Variable 

  1. Enter a name in the Label (Add User to Public Group or Queue) field – the API Name will auto-populate.
  2. Set Variable Values
    1. Row 1:
      1. Field: {!Loop_Through_Supported_Objects.QueueId}
      2. Operator: Equals
      3. Value: {!Create_Group_Queue}
  3. Click Done.

Step 1.6.4: Salesforce Flow – Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. Create a Record Collection Variable varRQueueSObject type Queue sObject to store record variable (created in step 1.6.3) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRQueueSObject}
      2. Operator: Add
      3. Value: {!Loop_Through_Supported_Objects}
  5. Click Done.

Step 1.6.5: Salesforce Flow – Adding a Create Records Element to Add a New User to Public Groups and Queues

  1. Under Toolbox, select Element
  2. Drag-and-drop the Create Records element onto the Flow designer. 
  3. Enter a name in the Label field- the API Name will auto-populate.
  4. For How Many Records to Create select Multiple.
  5. Map Record Collection: {!varRQueueSObject}
  6. Click Done.

Step 1.7: Lightning Flow – Adding a Get Record Element to Find the Members of Existing Public Group or Queue

The next step is to use the Get Records element to find the existing public group or queue members.  

  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 Group Member object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: GroupId
      2. Operator: Equals
      3. Value: {!varTQueueOrGroupId}
  7. How Many Records to Store:
    1. select All records
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

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

Now we will add a Decision element to check the Record Collection Variable from step 1.7 to find if it returns the record or not. Based on that, the Salesforce Flow will take the next step. 

  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 the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Group_Queue_Members}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done

Step 1.9: Salesforce Flow –  Add a Loop Element to Retrieve Records from Record Collection Variable (from step 1.7) 

  1. Drag-and-drop the Loop element onto the Flow designer. 
  2. Enter a name in the Label (Loop Through Supported Objects) field – the API Name will auto-populate.
  3. For Collection Variable select {!Get_Group_Queue_Members}.
  4. For Specify Direction for Iterating Over Collection select the option First item to last item.
  5. Click Done.

Step 1.10: Salesforce Flow – Adding an Assignment Element to Assign the Newly Created Public Group or Queue Id to the Loop Variable 

  1. Enter a name in the Label field – the API Name will auto-populate.
  2. Set Variable Values
    1. Row 1:
      1. Field: {!Loop_Through_Group_Members.GroupId}
      2. Operator: Equals
      3. Value: {!Create_Group_Queue}
  3. Click Done.

Step 1.11: Salesforce Flow – Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. Create a Record Collection Variable varRGroupMembers type Group Member to store record variable (created in step 1.10) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRGroupMembers}
      2. Operator: Add
      3. Value: {!Loop_Through_Group_Members}
  5. Click Done.

Step 1.12: Salesforce Flow – Adding a Create Records Element to Add Members to Newly Created Public group or Queue

  1. Under Toolbox, select Element
  2. Drag-and-drop the Create Records element onto the Flow designer. 
  3. Enter a name in the Label field- the API Name will auto-populate.
  4. For How Many Records to Create select Multiple.
  5. Map Record Collection: {!varRGroupMembers}
  6. Click Done.

In the end, Brenda’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: Screen Flow: Clone 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 Clone Group or Queue 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 Screen Flow: Clone Public Group or Queue flow
    2. Layout: Two Columns 
  6. Set Component Visibility
    1. Click + Add Filter
    2. Row 1:
      1. Permissions: Custom Permission > Clone_Group_or_Queue
      2. Operator: Equal
      3. Value: True
  7. Click Done.
  8. Once everything looks good, click the Save button. 

Proof of Concept

Now Onwards, any one can use this application to clone an existing Public group or Queue with members.  

  1. To clone a Queue, navigate to the Home tab and perform the steps, as shown in the video:

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!

Leave a Reply

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