+ Start a Discussion

Handling Large Queries Of > 50,000 in Apex Batch...

I have an Apex Batch job that I use to load a huge transaction file... And the code is running fine.

But what I want to know is, from within the Batch Apex class, if I have objects I need to query that may result in > 50,000 rows coming
back what is the best practice for handling this.

I was hoping I could use the Database.QueryLocator because I know they don't have the 50,000 limit
and was thinking I could do something like this mapping:

       Database.QueryLocator qlSSN      = Database.getQueryLocator([SELECT Id,payout__SSN__c FROM Account]);
       for(Database.QueryLocator a : qlSSN)

But this is not a valid approach. So how in Apex Batch, can you bring back a query that may be > 50,000.

Again, I am not talking about the DRIVER Apex Batch query being > 50,000 I am talking abount querying another Object from within the pocessing of the batch that may return over 50,000.

Thanks everyone.
Hi moverdorf,

When salesforce execute individual batch then the governal limits are enforced for the batch. for driver of the batch you can get >50k records, but not inside the batch. The limit is up to 50k when you are in the batch.

Vivek Patel.

Please like or mark this as best answer if this answers your query to help others find better answers and improve the quality of the developer forum.
Exactly why I am asking my question on how do developers handle the situation where inside the Apex Batch (non driving query) if you need to query more than 50,000 rows, what techniques are being used.