Getting Started with Process Builder – Part 24 (Automatically Add User to a Chatter Group)

Getting Started with Process Builder – Part 24 (Automatically Add User to a Chatter Group)

Last Updated on December 19, 2020 by Rakesh Gupta

To understand how to solve the same business use case using Salesforce Flow. Check out this article Getting Started with Salesforce Flow – Part 36 (Automatically Add New Users to a Chatter Group).

Big Idea or Enduring Question:

How do you automatically add users into a Chatter Group? 

Objectives:

This blog post will help us to understand the following

  • Create automation associated with creating a new user
  • Automatically add a user to a specified Chatter group
  • How to use the quick action in Process Builder
  • What is a MIXED DML error and how to avoid it?

Business Use case

Brenda David is working as a System administrator at Universal Containers (UC). Her next assignment is to create a process to auto add a new user to Chatter Group (UC Internal Announcements).

Automation Champion Approach (I-do):

The process of creating a new user can involve many steps that have to be repeated for each person. This can become time-consuming for admins. However, this process can be made easier with automation.

A few months back, I had written an article Getting Started with Lightning Flow – Part 36 (Automatically Add New Users to a Chatter Group) to discuss a way through which we can auto add a new user to Chatter Group. To achieve it, I had used Flow, Process Builder, and Workflow Rule. I got excellent feedback, so I wanted to share another way to do achieve the same business use case, using the Process Builder and Global Action. 

While this can be solved using various automation tools like Apex or Flow, we will use Process Builder. This is not something that can be accomplished with Workflow Rules. 

Before proceeding, ahead, understanding CollaborationGroupMember objects in Salesforce. It represents a member of a Chatter group.

Field Name Details
CollaborationGroupId Represent Id of the Chatter Group
MemberId Represent Id of the User (Group member)

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 8 steps to solve Brenda’s business requirement using Process Builder. We must: 

  1. Create a chatter group
  2. Find the chatter group Id
  3. Creating a custom label to store chatter group Id
  4. Define process properties
  5. Define evaluation criteria
  6. Define process criteria
  7. Set time for actions to execute
  8. Add action – quick actions 

Step 1: Create a Chatter Group

  1. Navigate to App Launcher and click on the Groups.
  2. Clicks on the New button. 
  3. Name the Group and make sure to select the Private Access Type.
  4. Click Save.

Step 2: Find the Chatter Group Id for UC Internal Announcements 

The next step is to find out the Id of the chatter group UC Internal Announcements. One possible workaround is to use the Developer Console. 

  1. Click Setup | Developer Console 
  2. In the Query Editor, run the following SOQL query 
    1. Select id, name from collaborationgroup where (name=’UC Internal Announcements’)
  3. Make sure to copy the Id. 

Step 3: Creating a Custom Label to Store Chatter Group Id

  1. Click Setup.
  2. In the User Interface, type Custom Labels.
  3. Click on the New Custom Label button.
  4. Enter Short Description the Name will auto-populate. 
  5. Now enter the UC Internal Announcement chatter group id in the Value.
  6. Click Save.

Step 4: 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.

Step 5: 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.

Step 6: 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 | IsActive
      2. Operator: Equals
      3. Type: Boolean
      4. Value: True
  5. Select All of the conditions are met (AND)
  6. Click Save.

Step 7: set time for actions to execute

When DML operations on certain sObjects sometimes referred to as setup objects (such as a User Object), along with, on the non-setup object (such as Accounts), in the same transaction, then, a Mixed DML error is thrown at a User.

The Mixed DML error is generated – when a User performs DML actions on Setup and non-Setup Objects in the same transaction -because some sObjects affect the user’s access to records in the org. Therefore, a user must insert or update these types of sObjects in different transactions to prevent operations from happening with incorrect access-level permissions. For example, a user cannot update an account, and a user role, in a single transaction. However, deleting a DML operation has no restrictions (reference Salesforce help).

We are adding time delays to avoid MIXED DML Errors.

  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.

Step 8: Add Action – Quick Actions

  1. Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
  2. For Action Type, select Quick Actions
  3. Name the action.
  4. Filter Search By: Type
  5. Type: Create a Record
  6. Action: NewGroupMember
  7. Set Quick Action Field Values:
    1. Row 1:
      1. Field: Member ID
      2. Type: Field Reference 
      3. Value: User | ID
    2. Click Add Row
    3. Row 2:
      1. Field: Related Record ID
      2. Type: Formula
      3. Value: System Variable | Label | UC_Internal_Chatter_Group_ID
  8. Click Save.

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

Note:- Before you activate your process, you will want to make sure that you have assigned data in the correct format because Process Builder obeys validation rules. If some fields are required by using validation rules, then make sure you have added those fields. Conversely, if some fields are required on the page layout, you can ignore those fields.

Proof of Concept

Now onwards, if a system administrator creates a new user, then Process Builder will automatically trigger and add the user to the UC Internal Announcement Chatter group.

  1. Now create a new user via the UI
  2. Once the user is created, they are automatically added to the chatter group UC Internal Announcements within a few seconds, as shown in the following screenshot:

Check Paused Flow Interviews 

  1. Click Setup.
  2. In the Quick Find box, type Paused Flow Interviews.
  3. Now you will see all action waiting for execution. 

Independent Practice (You-do):

Automatically add a user to a different user group based on their role or profile. 

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? 

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

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

15 thoughts on “Getting Started with Process Builder – Part 24 (Automatically Add User to a Chatter Group)

  1. This works for me, except every morning I get error emails from Salesforce to the effect that an “Error Occurred: insufficient access rights on cross-reference id”. Here’s part of the error log contained in that email, any ideas what might be causing this?:

    Error element myWaitEvent_myWait_myRule_1_event_0_SA1 (FlowActionCall).
    insufficient access rights on cross-reference id
    This report lists the elements that the flow interview executed. The report is a beta feature.
    We welcome your feedback on IdeaExchange.
    Flow Details
    Flow Name: Add_Active_User_to_Chatter_Group
    Type: Record Change Process
    Version: 2
    Status: Active
    Flow Interview Details
    Interview Label: Add_Active_User_to_Chatter_Group-2_InterviewLabel
    Current User: PeopleSoft User (0051a000000aWCJ)
    Start time: 3/20/2018 7:18 AM
    Duration: 44 seconds
    How the Interview Started
    PeopleSoft User (0051a000000aWCJ) started the flow interview.
    Some of this flow’s variables were set when the interview started.
    myVariable_old = null
    myVariable_current = 0051a000002yEnEAAU
    ASSIGNMENT: myVariable_waitStartTimeAssignment
    {!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
    Result
    {!myVariable_waitStartTimeVariable} = “3/20/2018 7:18 AM”
    DECISION: myPreWaitDecision_myWait_myRule_1
    Executed this outcome: myPreWaitRule_myWait_myRule_1
    Outcome conditions: and
    1. {!myVariable_current.IsActive} (true) Equals true
    Logic: All conditions must be true (AND)
    DECISION: myDecision
    Executed this outcome: myRule_1
    Outcome conditions: and
    1. {!myVariable_current.IsActive} (true) Equals true
    Logic: All conditions must be true (AND)
    WAIT: myWait_myRule_1
    The waiting conditions for the following wait events were met.
    Wait Event: myWaitEvent_myWait_myRule_1_event_0
    Waiting Conditions:
    1. {!myWaitEvent_myWait_myRule_1_event_0_postActionExecutionVariable} (false) Equals false
    Logic: All conditions must be true (AND)

    Event Type: Alarm: Relative Time
    Object Type = User
    Record ID = {!myVariable_current.Id} (0051a000002yEnEAAU)
    Offset Unit = Days
    Offset Number = 0
    Base Date/Time Field = CreatedDate
    Result
    Started waiting at 3/20/2018 7:18 AM.
    The interview started waiting at 3/20/2018 7:18 AM.
    The interview was resumed at 3/20/2018 7:19 AM by PeopleSoft User (0051a000000aWCJ).
    WAIT: myWait_myRule_1
    Wait event myWaitEvent_myWait_myRule_1_event_0 occurred.
    The following values from the event were assigned to flow variables.
    None.
    DECISION: myPostWaitDecision_myWaitEvent_myWait_myRule_1_event_0
    Executed this outcome: myPostWaitRule_myWaitEvent_myWait_myRule_1_event_0
    Outcome conditions: and
    1. {!myVariable_current.CreatedDate} (3/20/2018 7:18 AM) Is null false
    Logic: All conditions must be true (AND)
    COLLABORATIONGROUP.NEWGROUPMEMBER (QUICK ACTIONS): myWaitEvent_myWait_myRule_1_event_0_SA1
    Inputs:
    contextId = 0F91a000000DZT1
    MemberId = {!myVariable_current.Id} (0051a000002yEnEAAU)
    Error Occurred: insufficient access rights on cross-reference id

    1. To avoid the Mixed DML operation.

      DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction. However, deleting a DML operation has no restrictions.

  2. Thank you very much for this solution.I am trying for edit user, it works like charm except for the user that is already exist in the group, when we deactivate it and activate it back it throwing error saying that the user is already exist in group.My assumption is when the user is deactivated, salesforce will remove it from group member but when we activate it salesforce will add it into group member so the process builder will throw such error.

  3. Thank you for your last comment from January 19. I followed the instructions:

    I used: IsActive =True and profile lD= 00e30000001F1O7AAK ( Instead of using I’d use profile Name)

    Under criterion mode make sure to select “Do you want to execute the actions only when specified changes are made to the record – checked

    here is the error I got:

    Would you have a look and advise?

    Thank you very much. Kasia

    An error occurred at element myDecision (FlowDecision).
    The flow failed to access the value for myVariable_current.Profile.Name because it hasn’t been set or assigned.

    This report lists the elements that the flow interview executed. The report is a beta feature.
    We welcome your feedback on IdeaExchange.
    Flow Details
    Flow Name: Add_User_to_Global_Client_Care_Group
    Type: Workflow
    Version: 1
    Status: Active
    Flow Interview Details
    Interview Label: Add_User_to_Global_Client_Care_Group-1_User
    Current User: Kasia W (005a0000007hfFB)
    Start time: 21/01/2016 11:38
    Duration: 0 seconds
    How the Interview Started
    Kasia W (005a0000007hfFB) started the flow interview.
    Some of this flow’s variables were set when the interview started.
    myVariable_old = 00530000007IvvqAAC
    myVariable_current = 00530000007IvvqAAC
    ASSIGNMENT: myVariable_waitStartTimeAssignment
    {!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
    Result
    {!myVariable_waitStartTimeVariable} = “21/01/2016 11:38”

  4. Hi Rakesh,Would be possible to use this process “Automatically Add User to Chatter Group” in situations where the new user is created AND where profile is edited later on to meet certain criteria. In the step # 3 I want to choose – Select only when a record is created or edited. Please advise. Thank you very much, Kasia

      1. Hi Rakesh, you said it is possible by Including two conditions
        1) ISNEW true
        2) profile is changed from A to B

        Can you confirm when should I start the process?

        When recors is created
        or

        when records is created and edited?

        Many users have profile changes later in the future and want them in the group

        Can I just use conditions:

        IS active equals to true and ProfileID is equal 00e30000001F1O7AAK?

        Thank you

        Kasia

        1. Select when records is created and edited to start the Process.

          For condition select something like this

          1) isNew = True

          Or

          2) IsActive =True and profile lD= 00e30000001F1O7AAK ( Instead of using I’d use profile Name)

          Under criterion mode make sure to select “Do you want to execute the actions only when specified changes are made to the record?”

  5. Hi Rakesh,

    I created the flow as per above screenshot but received an error when i created new user record as below…

    Workflow Action Failed to Trigger Flow
    The record couldn’t be saved because it failed to trigger a flow.
    A flow trigger failed to execute the flow with version ID 301O00000000CPc.
    Contact your administrator for help.

    Can you please help with this ?

Leave a Reply

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