Getting Started with Process Builder – Part 57 (Automatically Add Partner User to Public Group) 

 Getting Started with Process Builder – Part 57 (Automatically Add Partner User to Public Group) 

Last Updated on December 5, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

How do you automatically add partner users to a public group? 

This is a continuation of my last article Getting Started with Process Builder – Part 56 (Auto Create a Public Group for new Account)In my previous article, I had discussed a use case, whenever an account is enabled as a Partner account, then automatically create a public group for it. This article goes a step ahead and explains, how someone utilizes the Flow and Process Builder to add Partner user from that account to Public Group automatically.

Objectives:

After reading this article, the reader will be able to:

  • Automatically add the newly created partner users to a public group
  • How to refer custom label in lighting flow
  • How to use a Decision element to find – record variable or record collection variable contains a record or not

Business Use case

Donna Serdula is working as a System Administrator at Universal Containers (UC). They have just implemented a partner community to manage their partner’s related work better in one place and help them to sell more. As a part of the partner onboarding process, once both parties sign the contract. The next steps are to create partner account and contacts in Salesforce, to grant them partner community access. Currently, at Universal Containers they have few manual processes that they want to automate are mentioned below

  • As a part of the partner onboarding process, the system administrator at Universal Containers manually creates a public group (Account Number for Name and DeveloperName) for each partner account. (Blog 56
  • Then add partner users from that account to Public Group, created in the preceding step. (Blog 57

Automation Champion Approach (I-do):

I’m going to explain the solution for the second requirement in this article. Blog 56 refers to the solution to the first requirement. There are a couple of solutions possible for the second business scenario, but I’ll use Process Builder and Flow to solve it Let’s take a pause here, familiar yourself with the Group and GroupMember objects in Salesforce.

Object Name Details
Group It represents a set of user records. The group 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 of the users below that role or territory in the hierarchy.
GroupMember It 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 to go through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 2 steps to solve Donna’s business requirement using Lightning Flow. We must:

  1. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a record variable to store user record details 
    3. Add a get record element to find public group record Id 
    4. Add a decision element to check the public group id from the record variable (from step 1.2)
    5. Add a create records element to add a user to the public group
  2. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Set time for actions to execute
    5. Add action – flows 

Step 1.1: Lightning 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 Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. Click Done.

Step 1.2: Lightning Flow – Add a Record Variable to Store User Record Data

A record variable is used to store all fields of a record. You can use the variable throughout your Flow. For example, while creating the record, performing an update, or with delete operations.

  1. Under Toolbox, select Manager, then click New Resource to store User record details.
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varRUser
    3. Data Type: Record
    4. Object User
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.3: Lightning Flow – Adding a Get Record Element to Find Public Group Id For Partner User’s Account

The next step is to find the Public Group Id for the partner user account. 

  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 Record Group object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: {!varRUser.Account.AccountNumber}
  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: Lightning Flow – Using Decision Element to Check the Public Group Id from 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 public group id 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: {!Find_Public_Group.Id}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.True}
  6. Click Done.

Step 1.5: Lightning Flow – Create Records – Add Partner User to Public Group

The final step is to add partner users to the public group, as soon as the Partner user account gets activated. We 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: GorupMember
    5. Set Field Values for the Group Member
    6. 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: {!varRUser.Id}
  3. Click Done.

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

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

Our next task is to create a Process Builder on the User object to start a Flow. To create a Process Builder on the User object follow the below instructions

Step 2.1: Define Process Properties

  1. Click Setup.
  2. In the Quick Find box, type Process Builder.
  3. Select Process Builder, then click New.
  4. Name the Process and click the Tab button. The API Name will populate. 
  5. As a best practice, always input a description
  6. The process starts when A record changes.
  7. Click Save.

Define Process Properties

–> Now you can create a process that another process can invoke. With invocable processes, you can reuse sections of your processes. Build one invocable process, call it from multiple processes or from multiple action groups in the same process. You can invoke processes with objects that share at least one unique ID. For example, in the Account and Contact objects, the AccountId field is unique to Account and also used by Contact. You can create an invocable process that updates a Contact record. Then you can invoke it from:

  • A process that updates an Account record’s billing address
  • A process that adds an Account status 

Step 2.2: Define Evaluation Criteria

  1. Click on the Add Object node to begin selecting the evaluation criteria.
  2. Select the User object from the dropdown list.
  3. Start the process only when a record is created.
  4. Click Save.

Evaluation Criteria

Step 2.3: Define Process Criteria

  1. Click the Add Criteria node to begin defining the process criteria.
  2. Name the criteria.
  3. The criteria should execute actions when the conditions are met.
  4. Set Conditions
    1. Row 1
      1. Field: User | AccountId
      2. Operator: Is null
      3. Type: Boolean
      4. Value: False
    2. Add Row
    3. Row 2
      1. Field: User | IsActive
      2. Operator: Equals
      3. Type: Boolean
      4. Value: True
  5. Select All of the conditions are met (AND)
  6. Click Save.

Step 2.4: set time for actions to execute

The next step is to set the time for scheduled action.

  1. Below Scheduled Actions, click Set Schedule.
  2. Set Field Values:
    1. Row 1:
      1. 0
      2. Hours
      3. After
      4. CreatedDate
  3. Click Save.

Set Schedule

Step 2.5: Add Action – Flows

  1. Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
  2. Below Scheduled Actions, click Add Action.
  3. For Action Type, select Flows
  4. Name the action.
  5. Select the flow we just createdAdd Partner User to Public Group.
  6. Set Flow Variables: 
    1. Row 1:
      1. Flow Variable: varRUser
      2. Type: Field Reference
      3. Value: Select the User record that started your process
  7. Click Save.

–> The reason behind to use time-based action is to avoid MIXED DML error. DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. It means we cannot perform DML Operation on both Setup and Non-setup object in a same context of execution.  7. Once done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot

In the end, Donna’s Process will look like the following screenshot:

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

Proof of Concept

Now onwards, if a system administrator creates a partner user, Process Builder will fire and automatically add them to their respective Public Group.  

  1. Navigate to the Account tab, then open an account Grand Hotels & Resorts Ltd. I have already enabled it as a Partner account in my last article Getting Started with Process Builder – Part 56 (Auto Create a Public Group for new Account). Grand Hotels & Resorts Ltd - Partner Account
  2. Partner Account Grand Hotels & Resorts Ltd has two contacts, as shown in the preceding screenshot. Now, I’m going to enable Tom Barr Contact as a Partner User. To do this open Tom Barr Contact, click on Manage External User and then, click Enable Partner User, as shown in the following screenshot:Enable Contact as Partner User
  3. It will redirect you to the new user setup screen, from where you can create a new user. Setup New Partner User
  4. Once done, click on the Save button. Wait for few minutes and then open the public group CD439877 (Click on Setup | Administer | Manage Users | Public Groups).

Proof of concept

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 #AutomationChampionPB.

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

6 thoughts on “ Getting Started with Process Builder – Part 57 (Automatically Add Partner User to Public Group) 

  1. Hi, thanks for sharing this, I always enjoy following this blog, many good ideas already came from what you are presenting here !
    I have one question: will the above work when you use DataLoader to insert a few hundred records at a time ?

    Reason I am asking is, I just had a similar setup with Process Builder and Flow, where process builder kicks off a flow that will add newly activated user’s to some Chatter groups. The flow would check if they maybe had been a member already before and then add them if not.
    The process works fine for single records, but as soon as you use DL with more than 200 users to be re-activated, it fails, giving me this error message:

    An error occurred at element Lookup_all_Chatter_Group_ID (FlowRecordLookup).
    MALFORMED_QUERY: FROM CollaborationGroup WHERE ( OR OR OR OR OR OR OR OR ^ ERROR at Row:1:Column:48 unexpected token: ‘OR’

    I don’t have more details right now and I was not able to do de-bugging, I was just wondering if your setup works with bulk records uploaded via DL.

    Thanks.

      1. Hi, with the help of Salesforce support we finally found the reason why my flow was crashing when updating with data loader, here is the explanation:

        The reason why it is failing is because of no filter condition added in the Fast Lookup screen “Lookup all Chatter Group ID”.

        Adding any filter value will solve this issue.

        This seems to be an issue and there is already an investigation raised with salesforce. This issue will be fixed in the next release (release 206).

        As a workaround for now, you can set the filter criteria in the Fast Lookup screen “Lookup all Chatter Group ID” something like below

        Field -> Id
        Operator -> is null
        Value -> {!$GlobalConstant.False}

        Interesting to know……

Leave a Reply

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