As per documentation , "A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed."
What is your usecase of having to process 50 million records ? You should make sure your queries are tuned properly to run as quickly and efficiently as possible.
I would recommend working on the SOQL query to make it more selective so that it returns less than 50 million records for you to be able to use in a batch apex.
Please see the below articles for tuning your SOQL query.
Working With Very Large SOQL Queries https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_VLSQ.htm
Make SOQL Query Selective https://help.salesforce.com/s/articleView?id=000325257&type=1
Also, if processing the records synchronously is not a strict requirement, consider using asynchronous processing options like Queueable Apex or Future Methods. These allow you to offload processing to separate execution contexts, providing more flexibility in handling large data volumes.
You can also consider using Bulk API(PK Chunking) https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/async_api_headers_enable_pk_chunking.htm
If this information helps, please mark the answer as best. Thank you
Due to a platform governor limit, it is not possible to retrieve more than 50 million records in batch apex. However if your query exceeds this limit, it will likely result in a limit exception.
To work around this limitation, you can use Batch chaining , that will allow you to have upto 5 batch job chained . For Example , First batch can proccess upto 45 million records and rest of the records can be send to another batch and than 2 batch can proccess further records.You may need to develop custom logic to filter the records that are being proccessed.
As per documentation , "A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed."
What is your usecase of having to process 50 million records ? You should make sure your queries are tuned properly to run as quickly and efficiently as possible.
I would recommend working on the SOQL query to make it more selective so that it returns less than 50 million records for you to be able to use in a batch apex.
Please see the below articles for tuning your SOQL query.
Working With Very Large SOQL Queries https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_VLSQ.htm
Make SOQL Query Selective https://help.salesforce.com/s/articleView?id=000325257&type=1
Also, if processing the records synchronously is not a strict requirement, consider using asynchronous processing options like Queueable Apex or Future Methods. These allow you to offload processing to separate execution contexts, providing more flexibility in handling large data volumes.
You can also consider using Bulk API(PK Chunking) https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/async_api_headers_enable_pk_chunking.htm
If this information helps, please mark the answer as best. Thank you
As per documentation , "A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed."
What is your usecase of having to process 50 million records ? You should make sure your queries are tuned properly to run as quickly and efficiently as possible.
I would recommend working on the SOQL query to make it more selective so that it returns less than 50 million records for you to be able to use in a batch apex.
Please see the below articles for tuning your SOQL query.
Working With Very Large SOQL Queries
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_VLSQ.htm
Make SOQL Query Selective
https://help.salesforce.com/s/articleView?id=000325257&type=1
Also, if processing the records synchronously is not a strict requirement, consider using asynchronous processing options like Queueable Apex or Future Methods. These allow you to offload processing to separate execution contexts, providing more flexibility in handling large data volumes.
You can also consider using Bulk API(PK Chunking) https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/async_api_headers_enable_pk_chunking.htm
If this information helps, please mark the answer as best. Thank you
All Answers
Due to a platform governor limit, it is not possible to retrieve more than 50 million records in batch apex. However if your query exceeds this limit, it will likely result in a limit exception.
To work around this limitation, you can use Batch chaining , that will allow you to have upto 5 batch job chained . For Example , First batch can proccess upto 45 million records and rest of the records can be send to another batch and than 2 batch can proccess further records.You may need to develop custom logic to filter the records that are being proccessed.
As per documentation , "A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed."
What is your usecase of having to process 50 million records ? You should make sure your queries are tuned properly to run as quickly and efficiently as possible.
I would recommend working on the SOQL query to make it more selective so that it returns less than 50 million records for you to be able to use in a batch apex.
Please see the below articles for tuning your SOQL query.
Working With Very Large SOQL Queries
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_VLSQ.htm
Make SOQL Query Selective
https://help.salesforce.com/s/articleView?id=000325257&type=1
Also, if processing the records synchronously is not a strict requirement, consider using asynchronous processing options like Queueable Apex or Future Methods. These allow you to offload processing to separate execution contexts, providing more flexibility in handling large data volumes.
You can also consider using Bulk API(PK Chunking) https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/async_api_headers_enable_pk_chunking.htm
If this information helps, please mark the answer as best. Thank you
Thank you for your ansewr.