Invoking Batch Apex
There are several different ways in which we can invoke a Batch Apex class to run, which will be useful in different circumstances and use cases. In this section, we will review the different ways in which you can invoke Batch Apex and when each of them might be applicable. We will also discuss some ways in which you can utilize several Salesforce features at the same time so that you can invoke Batch Apex in a more dynamic and configuration-controlled fashion. Let’s begin.
Using Database.executeBatch
The first way to invoke Batch Apex is by using the standard Database.executeBatch()
method. This method takes in an instance of a class that implements the Database.Batchable
interface and a second optional parameter to define the size of the scope of each batch. As mentioned in the The base interface section, for implementations that use QueryLocator
instances, this defaults to 200 records and has a maximum value of 2,000 records, while for implementations...