Salesforce Flow: Add Users to Public Group Without Code

As a Salesforce admin, I’m responsible for managing user access, permissions, and organization security. In our organization, there are different roles such as Sales Employee, Manager, and HR.

Now, according to the user role, I need to assign that user to the respective group. For example, if the user is in the Sales Employee role, then I need to add them to the Sales group.

Now, the requirement is that whenever a new user account is created or an existing account is updated, I want to automatically add the user to the public group according to the user’s role.

In this article, we will learn about how to add users to public group using Salesforce Flow. In this, I will explain what a public group is and how we can add newly created user to the public group according to their roles.

What is a Public Group in Salesforce?

In Salesforce, a public group is a collection of users that enables easy sharing of records or setting of permissions for multiple users at once, rather than assigning access individually.

For example, we have a public group named ‘Support Team’ that includes five support users. Now, instead of sharing a case record with each user, you can share it with the group.

Below you can see the public group that I created for sales and service users. Now using the flow, I want to automate the process when any new user is created or an existing user is updated. According to their role, they should be added to the group.

Create Public Group in Salesforce

We also require the User Role ID, which we will use in the flow to determine which public group should be assigned to the specific user role.

For that, I used the SOQL query to retrieve the IDs of the user roles.

Retrieve User Role ID Using SOQL

Add Users to Public Group Using Salesforce Flow

Using the above scenario and the following steps, we can automatically add users to a public group using Salesforce Flow.

Click on the Setup. -> Home Page. -> In the Quick Find Box, Search for Flows. You will see an option under Process Automation. -> Click on Flows.

In the flows setup window, click on the button New Flow -> Start From Scratch -> select the Record Trigger Flow -> Next.

In the start element, we have to select the object on which we want to perform automation. In our scenario, the User is a triggering object.

In Configure Trigger, I have selected A Record is Created or Updated because when we create or update a role, the flow should trigger.

Then, we don’t need to Set Entry Conditions. We are going to add a newly created user to the public group, so we have to select Optimize the Flow for Action and Related Records.

Add New User to Public Group Using Salesforce Flow

Next, we need to select the Get Records element by clicking on ‘+ Add Element‘ and then enter a Label and API Name into it.

To retrieve the public groups that we have created for this scenario. Select the Group object.

Then, to Filter Records for the object, we need to add a condition:

  1. In the Field option, you will see all fields from the Group. There, we need to select the Developer Name.
  2. Equals operator.
  3. In the Value, we need to select which group we want to retrieve from the object.
Add New User to Public Group From Salesforce Flow

To assign the public group according to the role, we need to add a Decision element that checks the user’s role. Then, by adding the Create Record element, we will assign the respective public group to that user.

In this condition, we need to provide the User Role ID that we retrieve using a SOQL query. For this, you need to add the number of outcomes corresponding to each role.

Add New User to Public Group From Salesforce Flows

Now, we need to assign a newly created user to the Group. To do this, add a Create Record element and enter a Label and API Name into it.

Now, we are going to add a user to the group. For that, in the “Create a record of the Object” sectionselect Group Member.

Enter the following conditions for Set Field values for the Group Member. In the Field, you will see the Group Member’s fields, and in Value, you will see the User’s fields; you have to assign the User’s field to the group member field as follows:

  • GroupID (From Group Member) = GroupID (From Get Record Element).
  • UserOrGroupId (From Group Member) = UserID (From User Object).
Salesforce Flows Add New User to Public Group

Now we are ready to save the flow. For that, click the Save button, provide the flow Label, and the API Name will be automatically populated.

After that, always debug the flow before activating it to ensure that the working flow is correct and that there are no runtime errors. Then activate the flow.

How to Add User to Public Groups using Salesforce Flows

In this way, we can automate the process of adding a user to the public group using Salesforce Flow.

Proof of Concept:

In the screenshot below, you can see the users that we have in the Sales Group. Now we will update the existing user role for their account.

Salesforce Flow add Users to Public Groups

Now, we will test the flow to see if it adds the new user to the respective public group. To do that, navigate to the User details page. Open any Active User record.

  1. Now, I update the User Role according to our scenario and save the record.
  2. I have assigned the Sales Employee Role to the John Joy user, which means he should get added to the Sales group as per the logic we defined.
Add User yo Public Groups using Salesforce Flow

Here, as you navigate to the Public Group, you can see that the user we just created has been assigned to the group.

Add User to Public Groups using Salesforce Flows

This is how we can automatically add users to public groups using Salesforce Flow.

Conclusion

I hope you have got an idea about how to add users to a public group using Salesforce Flow. In this, I have explained what a public group is and how we can add newly created user to the public group according to their roles. This helps us automate the process of adding a user to the respective group based on their role.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.