Activity › Forums › Salesforce® Discussions › What is database.getQuerylocator in Salesforce?
-
What is database.getQuerylocator in Salesforce?
Posted by Avnish Yadav on August 3, 2018 at 12:37 PMWhat is database.getQuerylocator in Salesforce?
Parul replied 7 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Avnish,
Database.getQueryLocator returns a Query Locator that runs your selected SOQL query returning list that can be iterated over in bathc apex or used for displaying large sets in VF (allowing things such as pagination).
The query locator can return upto 50 million records and should be used in instances where you want to bactha a high volume of data up (pagination or batch apex). The database.query method should be used in instances where you are wanting to do a dynamic runtime SOQL query for your code.
Hope that helps.
Thanks.
- [adinserter block='9']
-
Hi,
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 but we can retrieve up to 10,000 records.
To add more –
Database.query():
We can retrieve up to 50,000 records.
If VF page has read-only attribute, use Database.getQueryLocator().
In Batch Apex, if we use Database.query(), it supports 50,000 records only.String fieldName = ‘Name,Phone’;
String dynQuery = ‘select Id ‘ + fieldName + ‘ From Account’;
Database.query(dynQuery);Hope this helps.
-
Database.getQueryLocator in Salesforce returns a Query Locator that runs your selected SOQL query returning list that can be iterated over in batch apex or used for displaying large sets in VF
Thanks
Log In to reply.