Difference between Database.query() and Database.getQueryLocator



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

Cheers!!!

5 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
  2. 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