+ Start a Discussion

database.query locator in apex class

Hi Team,

can we use database.querylocator in apex class 

AbhishekAbhishek (Salesforce Developers) 
database.getQueryLocator 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 (allowing things such as pagination). 
The query locator can return up to 50 million records and should be used in instances where you want to batch 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.

For further reference, you can check the below,

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.