+ Start a Discussion
Vijay ummedaVijay ummeda 

database.query locator in apex class

Hi Team,

can we use database.querylocator in apex class 

Thanks,
Vijay.
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,
https://salesforce.stackexchange.com/questions/239868/database-query-locator-vs-simple-query#:~:text=2%20Answers&text=answer%20was%20accepted%E2%80%A6-,Database.,million%20records)%20in%20an%20org.


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.

Thanks.