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

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.”
    Salesforce: Process Builder — Create a Process Page to Add New Users to Group
  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:
    Salesforce: Process Builder — Criteria for Adding New Users to a Group
  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:- Related Record ID: enter your Chatter / Community Cloud group ID here. It will look something like this: 0F91I000000kJRqSAM
    Member ID: select “Reference”, and look for User ID.Salesforce: Process Builder — Quick Actions for Adding New Users to Group
  7. You’re set! Remember to activate this process.

Here’s how the final process looks:

Salesforce: Process Builder — Add New Users to Group Process Map

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

Salesforce: Demo — Automatically Adding New Users to a Group by Using Process Builder

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.

Leave a Reply

Your email address will not be published. Required fields are marked *