May 31, 2013

Difference between Database.query() and Database.getQueryLocator

Database.query()
We can retrieve up to 50,000 records.
If VF page doesn’t have read only attribute, use Database.query().
In Batch Apex, if we use Database.query(), it supports 50,000 records only.
 
Database.getQueryLocator
We can retrieve up to 10,000 records.
If VF page have read only attribute, use Database.getQueryLocator().
In Batch Apex, if we use Database.getQueryLocator(), it supports upto 50 million records.

4 comments:

  1. Database.query() is used to construct dynamic SOQL query at runtime instead of using inline SOQL query. Database.getQueryLocator() is the return type of the start method in batch apex code.

    ReplyDelete