Last Updated on December 12, 2017 by Rakesh Gupta
After Clone Chatter group with members article, I got lot’s of Emails/Messages from people wants to know about how they can clone “Public Group or Queue. Before going ahead I want to say big thanks to Mr. Mark Ross to feature my #Sp14FlowHackathon idea in his article. In this article, I will discuss how a Salesforce administrator can build an application using Flow to Clone Public Group or Queue.
Business Use Case
As a Salesforce admin many times you got the requirement to create one Public Group similar to existing group X (In our case we will say Public Group Sales Managers) and add few more users into it.
Solution for the above business requirement
Again this is the power of Visual Workflow, we will create an app without using a single line of code. Before proceeding ahead you have to understand Group and GroupMember objects in Salesforce.
- Group: – This Group object represents Queue and Public Group both. Groups are sets of users. A Group 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.
Note: – In this article, I will only discuss clone Public group. In the similar fashion, ou can develop a flow for the Queue.
To develop this application follow the below instructions
1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
2) Click on New Flow, it will open flow canvas for you
3) Drag and drop a Screen ( Give the name Clone Public Group) on the window, add Three fields with below details
Name | Data Type | Required |
Old Group ID | Textbox | Yes |
Textbox | Textbox | Yes |
Grant Access Using Hierarchies | Checkbox | No |
It will look like the below screenshot
4) Drag and drop a Record Create ( Give the name Create Public Group) onto the window to create a new Public group and map the fields according to below details
- Select Object Group
- Name= {!New_Group_Name} [ This is nothing but Screen Input]
- Type=Regular
- DoesIncludeBosses={!Grant_Access_Using_Hierarchies} [ This is nothing but Screen Input], Save Id of record into any variable in our case it’s {!NewGroupId}. You can take help from the following screenshot
Note: – For Queue set Type = Queue and remove the field DoesIncludeBosses from Record Create element and add another field as per your choice.
5) The next task is to get the list of the member id from the old Public Group for cloning. To do this Drag and drop a Fast Lookup( Give the name Extract all members from old group) and map the field according to the below screenshot and save the field UserOrGroupId value into Sobject Collection in our case it’s {!OldMembersID}
6) Now our next task is adding members to the new group. For this we will use Loop, Assignment and Fast Create. To do this Drag and drop a Loop ( Give the name Extract memebrs one by one) and loop through Sobject Collection {!OldMembersID} and save current value in New Sobject Varibale {!OneByone} as shown in the following screenshot
7) Now Drag and drop an Assignment Logic ( Give the name Assign New Group ID) and assign {!NewGroupId} to Sobject Varibale {!OneByone.GroupId}, as shown in the below screenshot
8) Drag and Drop Assignment Logic (Give the name Mass Add) on the window and assign the value from Sobject variable {!OneByone} to Sobject Collection variable {!AllinOne} so at the end of for loop (To avoid SOQL limit), it will add all members from old Public group to new Public Group. Take the help from the below screenshot
9) Finally, drag and Drop Fast Create (Give the name Add Members In New Group) on the window and map the field according to the below screenshot
Finally our Flow will look like the following screenshot
10) Save the flow with name Clone Public Group or Queue and close the canvas.
Add Visual workflow into the home page component
We can call Flow from a custom button, link, sub-flow, Visualforce page, Apex start() or using Flow Trigger workflow action. Here we will call our flow from the homepage component. To do that follow below instruction
1) Create custom link from Name | Setup | App Setup | Customize | Home | Custom link
2) Add custom link in the Home page component
3) Add Home page component into the Home page layout
It’s time to test this feature
1) In this demo, I will Clone Public Group “Sales Managers“, as a first step copy the ID of Public Group “Sales Managers”
2) To open this app click on “Clone Public Group” link available on the homepage, and fill the details you can take help from below screenshot
3) Click on Next button and you are done. Below is the proof of concept
I will suggest you Implement this first on your developer org test it and then move it to Production.