ProcessBuilder and Bulkification

ProcessBuilder and Bulkification - Tread Carefully

Since it's launch, Process Builder from Salesforce has gained a lot of functionality. 

In many cases, it can now be used to automate actions that were only previously available with a custom Apex Trigger - in some instances!

The full list of functions possible in Process Builder are listed on this page but some of the most common requirements are:
  • Create a record
  • Update any related record—not just the record or its parent
  • Use a quick action to create a record, update a record, or log a call
  • Invoke a process from another process
  • Launch a flow—you can’t schedule this action with workflow
  • Send an email
  • Post to Chatter
  • Submit for approval
The ability to update related record(s) is one of the most popular features, but it comes with a caveat.

Bulkification - What?

Despite being quite a clunky word to say, Bulkification is a really useful concept to bear in mind when developing in Salesforce. 

In essence, it means making sure that your automated process runs with both a small number of records, and works equally when when processing a large volume of data.

Bulkification in Process Builder

You may be forgiven for thinking that Process Builder handles Bulkification for you (I certainly did at first) but it doesn't - yet.

If you don't consider Bulkification in Process Builder you will see lots of strange error messages coming through very quickly.

A simple example

I went to see a customer last week who had a simple Process Builder set up, but were receiving error messages constantly.

Their Process Builder was being used to make sure all related Tasks & Activities were marked as Closed when a Contact was marked Inactive. 

After all, why would you continue to call/email customers after they had 'opted out' or left their current company.

The Error

After they had activated the flow, all ran well for a while but suddenly they were receiving several error messages per hour.

The standard error message looks like this. It can be tricky to work out what it means.

The Cause

This flow message is basically saying that Salesforce hit a limit of the number of iterations that it could loop through.

To picture this, imagine 
  • One Contact who had received: 
    • 1 phone call and 
    • 1 email whilst the company had been talking to them 
(2 Task records to update) 

Compare this to a long term customer who might have received multiple emails, calls, meeting invitations and other types of activity whilst they were Active.
  • One Contact
    • 1 phone call
    • 1 meeting
    • 1 update email
    • 1 meeting request
    • 1 marketing email
    • 1 phone call
    • 1 email
    • 1 follow up 
(8 Task records to update) 

This customer was trying to update ALL Tasks related to the Contact each time they were marked Inactive and quite simply they were hitting a Salesforce limit.

The Fix

In this instance, I was able to stop the error messages from occurring by limiting down the scope of the Process Builder action. 

Instead of trying to update ALL tasks, I changed it to the most recent Tasks. I also added a criteria to ensure that only Tasks without an Account Name were updated.


If the customer needed to ensure that ALL Tasks were updated, I would have needed to create a Trigger action instead to handle this update.

Ideas

Several people have commented/logged ideas with Salesforce about handling bulkification with Process Builder in a different way.
In Summer 17, the error message for Process Builder is also going to include a link to the 'Offending' Flow that is hitting the limits. Thanks for pointing that out @DouglasCAyers.



To learn more about Process Builder, check out the official Trailhead Module.

Image from Pexels.com, artist Pixabay

Comments