Invoking Batch Apex
There are a number of 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 a number of Salesforce features together to allow you to invoke Batch Apex in a more dynamic and configuration controlled fashion. Let's begin with the first one.
Using Database.executeBatch
The first way to invoke Batch Apex is through the use of the standard Database.executeBatch()
method. This method takes in an instance of a class implementing 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 using QueryLocator
instances, this defaults to 200 records and has a maximum value of 2,000 records...