Automatically Add Partner User to Public Group

Automatically Add Partner User to Public Group

Last Updated on March 27, 2022 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 Salesforce Flow to add Partner users 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 create and refer formula in salesforce 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 step is to create partner accounts and contacts in Salesforce that will grant them partner community access. Currently, at Universal Containers they have a few manual processes that they want to automate, which 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. (Process Builder Blog 56
  • Then add partner users from that account to Public Group, created in the preceding step. (Salesforce Flow Blog 102

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.

To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario.

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 going through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 6 steps to solve Donna’s business requirement using Record-Triggered Flow. We must:

  1. Define flow properties for record-triggered flow
  2. Formula to determine whether the user is created or updated
  3. Add a decision element to check if the user has accountid populated
  4. Add a get record element to find public group record Id 
  5. Add a decision element to check the public group id from the record variable (from step 4)
  6. Add a create records element to add a user to the public group

Step 1: 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 Record-Triggered Flow option, and click on Create and configure the flow as follows:
    1. Object: User
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2: Formula to Determine Whether the User  is Created or Updated

  1. Under Toolbox, select Manager, then click New Resource to determine whether the record is new or old.
  2. Input the following information:
    1. Resource Type: Formula
    2. API Name: forB_IsNew
    3. Data Type: Boolean
    4. Formula: IsNew()
  3. Click Done.

Step 3: Using Decision Element to Check if User has AccountId Populated

Now we will use the Decision element to check if accountid is populated on the user.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.AccountId}
      2. Operator: Is Null
      3. Value: {!$GlobalConstant.False}
    2. Add Condition
    3. Row 2
      1. Resource: {!forB_IsNew}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 4: 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. On Flow Designer, below the Yes node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Record Group object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: {!$Record.Account.AccountNumber}
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

Step 5: Using Decision Element to Check the Public Group Id from the Record Variable (from step 4)

Now we will use the Decision element to check the Record Variable from step 4 to find if it returns the public group id or not.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Find_Public_Group}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
    2. Click Done.

Step 6: Add Create Records Element to Add a Partner User to the 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. On Flow Designer, below the Group Found node, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Input the following information:
    1. How Many Records to Create: One
    2. How to Set the Record Fields: Use separate resources, and literal values
    3. Object: GorupMember
    4. Set Field Values for the Group Member
    5. 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: {!$Record.Id}
  4. 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: 54
  5. Interview LabelRecord-Triggered: User After Save {!$Flow.CurrentDateTime}
  6. Click Save

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

Proof of Concept

Now onwards, if a system administrator creates a partner user, Salesforce Flow 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 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 is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

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

6 thoughts on “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.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading