Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Large Data Processing with Cursors and Queueable Apex Versus Batch Apex
With Apex Cursors, you create a pointer to a large SOQL query result set of up to 50 million rows. The cursor can traverse the result set in chunks across multiple transactions. If you combine a Cursor with a chained Queueable job, each execution processes one or more chunks of records and then re-enqueues itself to handle the next chunk, until all records are processed. This approach has two key advantages over Batch Apex:
- No parallel batch slot consumption. A chained Queueable job chain counts as a single logical process. It doesn’t consume Batch Apex slots or accumulate in the Flex Queue.
- Flexibility at scale. Queueable jobs with Cursors can scale the chunk size to adapt to different processing requirements for individual records.
For a sample implementation, see Apex Cursors.
Cursors and Queueables Versus Batch Apex
| Detail | Batch Apex | Cursors+Queueable |
| Parallel Batch Slot Usage | Yes. Counts against the 5-job limit. | No |
| Flex Queue Contention | Yes | No |
| Execution Model | Ordered and sequential with a fixed scope size | Developer-defined order, sequence, and fetch size |
| Error Isolation | Per Batch chunk | Transaction Finalizer Per Queueable transaction via a Transaction Finalizer |