Skip to content

Example: Schedule Mass Actions with Process Builder, Flow, or Apex

Doug Ayers edited this page Feb 3, 2019 · 3 revisions

Home > Examples > Schedule Mass Actions with Process Builder, Flow, or Apex


Overview

The main use case for Mass Action Scheduler is to declaratively define a schedule for Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, and Apex to process records from Reports and List Views. However, you may want to have your configuration run for more arbitrary reasons than an always recurring schedule like every hour or the 1st of every month.

Using Process Builder, Flow, or Apex you can have more granular control when a Mass Action Configuration runs by calling an Apex action called ingeniously Run Mass Action.

For example, with Process Builder you could wait for certain record conditions to occur or listen for Platform Events before running a Mass Action Configuration. Or, with Flow you could have a support agent walk through screens and when conditions right then run a Mass Action Configuration.

Process Builder Instructions

First, create a Mass Action Configuration record.

Second, create a process and define one of it's Immediate Actions or Scheduled Actions an Apex Action Type that calls the apex class labeled Run Mass Action. It accepts one input variable, the Mass Action Configuration record's Salesforce ID.

screen shot

Now anytime your process runs and meets your criteria then it will also run your Mass Action Configuration in the background.

Flow Instructions

First, create a Mass Action Configuration record.

Second, create a flow and drag the Apex element named dca_mass_action__MA_RunConfigInvocable to the canvas. It accepts one input variable, the Mass Action Configuration record's ID. It returns one output variable, the backaground apex job ID.

screen shot

screen shot

screen shot

Now anytime your flow runs and meets your criteria then it will also run your Mass Action Configuration in the background.

Apex Instructions

First, create a Mass Action Configuration record.

Second, call the dca_mass_action__MA_RunConfigInvocable with a list of one or more requests. Each request will submit as a separate background apex job the Mass Action Configuration record.

dca_mass_action.MA_RunConfigInvocable.Request req = new dca_mass_action.MA_RunConfigInvocable.Request();
req.configId = <your config id>;

List<dca_mass_action.MA_RunConfigInvocable.Response> responses = dca_mass_action.MA_RunConfigInvocable.execute( new List<dca_mass_action.MA_RunConfigInvocable.Request>{ req } );

for ( dca_mass_action.MA_RunConfigInvocable.Response res : responses ) {
    System.debug( res.jobId );
}
You can’t perform that action at this time.