Processing large volumes of records is a common requirement in Salesforce. Traditionally, Batch Apex has been the preferred approach for processing large datasets asynchronously.
With the introduction of Apex Cursors, developers now have another option for working with large SOQL result sets. Apex Cursors became generally available in Spring ’26 (API version 66.0) and provide more control over how records are retrieved and processed.
But does this mean Apex Cursors replace Batch Apex?
No. Both have different purposes and should be selected based on the requirement.
What is Batch Apex?
Batch Apex is an asynchronous framework that allows Salesforce developers to process large numbers of records in smaller groups.
A Batch Apex class contains three main methods:
- start() – identifies the records.
- execute() – processes each batch.
- finish() – performs post-processing.
If there are thousands of records, Salesforce processes them in multiple transactions.
Records
↓
Batch Apex
↓
200 → Execute
200 → Execute
200 → Execute
↓
Completed
A major advantage is that each execute() runs in a separate transaction, so governor limits are reset for each batch.
What are Apex Cursors?
Apex Cursors allow developers to work with large SOQL result sets by retrieving records in smaller chunks.
Unlike Batch Apex, the developer controls the position and number of records retrieved.
Example
Database.Cursor cursor = Database.getCursor(
'SELECT Id, Name FROM Account ORDER BY Id'
);
Integer totalRecords = cursor.getNumRecords();
Integer position = 0;
Integer chunkSize = 200;
while (position < totalRecords) {
Integer fetchSize = Math.min(
chunkSize,
totalRecords - position
);
List<Account> accounts =
cursor.fetch(position, fetchSize);
for (Account acc : accounts) {
System.debug(acc.Name);
}
position += accounts.size();
}
The records are retrieved progressively:
Cursor
↓
fetch(0, 200)
↓
fetch(200, 200)
↓
fetch(400, 200)
↓
Continue…
This provides greater control over how the result set is processed.
Apex Cursors vs Batch Apex
| Feature | Batch Apex | Apex Cursors |
| Primary purpose | Large-scale processing | Large result-set retrieval |
| Processing control | Salesforce-managed | Developer-controlled |
| Chunk size | Batch size | fetch() size |
| Separate transactions | Yes | No |
| Governor limits reset | Yes | No |
| Large datasets | Excellent | Excellent |
| DML processing | Excellent | Possible |
| Queueable integration | Possible | Useful |
| Best for | Bulk processing | Flexible processing |
Governor Limits
One of the biggest differences is transaction handling.
With Batch Apex:
Batch 1 → Transaction 1 → Limits
Batch 2 → Transaction 2 → Limits Reset
Batch 3 → Transaction 3 → Limits Reset
With Apex Cursors, calling fetch() does not automatically create a new transaction.
Therefore, Apex Cursors do not bypass governor limits. They mainly provide controlled access to a large query result set.
When Should You Use Batch Apex?
Choose Batch Apex when:
- You need a large-scale DML.
- You need separate transactions.
- You need governor limits to reset between batches.
- You need scheduled or background processing.
- Records can be processed independently.
Examples: Data cleanup, mass updates, data migration, and scheduled synchronization.
When Should You Use Apex Cursors?
Consider Apex Cursors when:
- You need to process a large SOQL result set.
- You need control over the fetch size.
- You need control over the position of retrieved records.
- You are building a custom processing solution.
- You want to combine cursor processing with Queueable Apex.
Conclusion
Apex Cursors do not replace Batch Apex. Instead, they provide Salesforce developers with another option for handling large datasets.
Batch Apex is ideal when you need Salesforce-managed asynchronous processing with separate transactions.
Apex Cursors are useful when you need more control over how a large SOQL result set is retrieved and processed.
The key is to choose the approach based on the requirement rather than simply choosing the newer feature.
By following the above blog instructions, you will be able to learn “Apex Cursors vs. Batch Apex: Which Salesforce Data Processing Approach Should You Use?“. If you still have queries or any related problems, don’t hesitate to contact us at salesforce@greytrix.com. More details about our integration product are available on our website and Salesforce AppExchange.
We hope you may find this blog resourceful and helpful. However, if you still have concerns and need more help, please contact us at salesforce@greytrix.com.
About Us
Greytrix – a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.
Greytrix has some unique solutions for Cloud CRM such as Salesforce Sage integration for Sage X3, Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data Migration, Integrated App development, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star rated app listed on Salesforce AppExchange.
The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.
For more information on our Salesforce products and services, contact us at salesforce@greytrix.com. We will be glad to assist you.
Related Posts: