When to use Batch Apex
Batch Apex has a number of key use cases, which we will discuss here. But before discussing them, it is worth spending some time understanding how Batch Apex processes data.
As we will see in the following diagram, Batch Apex is great for working with large volumes of data. When utilizing Batch Apex, we define a set of data to be iterated over, either through a query or a custom iterable. Salesforce then chunks this data into batches and processes the batches one by one. So, if we had 200,000 records to process and wanted to process them in batches of 1,000, Salesforce would chunk the job into batches of 1,000 and process them one by one.
Refer to the following diagram:
This makes Batch Apex fantastic at some tasks and less useful at others. Let's now look through some use cases where having these processes executed in a sequential series of batches makes the most sense.