[SalesForce] Governor limits : Database.getQueryLocator

Why the Salesforce Governor Limits cheatsheet show the following?

Total number of records retrieved by Database.getQueryLocator —> 10000

What does this mean?

The limits are reset for every execute(), not for every start() execution, so the records are retrieved in a single start() call and I'm able to retrieve much more than 10k records by a getQueryLocator.

What does the trick?

Best Answer

According to the documentation, in a batch start() method the governor limit is bypassed. The governor limit of 10,000 in the limits cheatsheet still applies in execute() and finish() and other methods.

Use the Database.QueryLocator object when you are using a simple query (SELECT) to generate the scope of objects used in the batch job. If you use a querylocator object, the governor limit for the total number of records retrieved by SOQL queries is bypassed. For example, a batch Apex job for the Account object can return a QueryLocator for all account records (up to 50 million records) in an organization. Another example is a sharing recalculation for the Contact object that returns a QueryLocator for all account records in an organization.