X

Auto-Add New Users to Community Groups with Process Builder

As a community manager or a Salesforce admin, you may need to automatically add new users to a group on Chatter or Community Cloud.

While you can use Visual Workflow (Flow) or an Apex trigger to achieve this, the good news is: you can do the same thing with Process Builder! As Salesforce admins always say, you can accomplish many things with clicks, not code.

 Objective

When new users are created, they are automatically added to a specific group on Chatter or Community Cloud.

Estimated Time

~15 minutes

 Requirements

  • Working knowledge of Process Builder
  • Your community is small- to medium-sized (Process Builder has scalability issues)

Create a Process in Process Builder

  1. Visit Setup-> Process Builder.
  2. Give the process a name. Under “The process starts when” field, select “A record changes.”
  3. Next, select an object that starts the process. Click “Add Object”, select the User object, and keep it as “only when a record is created”. Hit “Save.”
  4. Click “Add Criteria” and fill it in as follows:
  5. This next step would seem surprisingly unintuitive (I’ll expand more on this in the section below). Under “Scheduled Actions“, click “Set Schedule” and set it as the following:

    Salesforce: Process Builder — Scheduled Actions for Adding New Users to Group

  6. Under the same “Scheduled Actions” box, click “Add Action”. Select “Quick Actions” and give the action a name. Under Filter Search By, select “Type”, followed by “Create a Record”, and “New Group Member.” Set the Quick Action Field Values as the following:
    1. Related Record ID: enter your Chatter / Community Cloud group ID here. It will look something like this: 0F91I000000kJRqSAM
    2. Member ID: select “Reference”, and look for User ID.
  7. You’re set! Remember to activate this process.

Here’s how the final process looks:

It would be remiss of me to not test it out to make sure it actually works:

Why Scheduled Actions Are Used Instead of Immediate Actions

If you use Immediate Actions like I did and tried to create a new user, you’ll run into an unhelpful error message:

“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 xx. Contact your administrator for help.”

You may also receive a detailed flow error email that may include something like this:

Error element myRule_1_A1 (FlowActionCall).
DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CollaborationGroupMember, original object: User”

The User object is considered as a setup object, while CollaborationGroupMember is a non-setup object.

According to the official Salesforce documentation:

“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.

The workaround of using a scheduled action (that also executes immediately) instead of immediate action allows the process to run in a different transaction, thus making our process work.

Wrapping Up

While you can use programmatic options like Apex triggers to automate adding new users to a Chatter / Community group, declarative tools like Process Builder can do the same thing.

(Visited 1,844 times, 1 visits today)
Clement Z. Chan: @saigoheikiSeized by a wanderlust that never quite goes away, Clement currently works for a nonprofit in New York.