Activity Forums Salesforce® Discussions What is database.getQuerylocator in Salesforce?

  • Prachi

    Member
    August 8, 2018 at 6:54 am

    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.

  • shariq

    Member
    September 16, 2018 at 5:15 pm

    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.

  • Parul

    Member
    September 16, 2018 at 5:46 pm

    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.

Popular Salesforce Blogs

Popular Salesforce Videos