function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KaityKaity 

Difference in Query() and QueryMore()

What is the difference between Query() and QueryMore()? Can you please explain with a usecase? I have read the blogs of SalesForce but didnot understand.

-Kaity
BalajiRanganathanBalajiRanganathan
QueryMore is used to implement the pagination.

1)Initally you call the query to get the initial set of recrods(500 rows of data by default and you override the batch size). the query methods gives you the query result object.
2) we use the isDone method to check if there are more batches of record.
3) If isDone is false, then you use the queryMore method by passing the query locator object which has the details about the current batch of records (startrow and endrow etc) returned to get the next batch of record.

the following will give you the more detail.

https://www.salesforce.com/developer/docs/api/Content/sample_query_calls.htm
KaityKaity
Please validate:
So, we have to use first query()methods, if records are morethan 500, then we have to use querymore() after checking IsDone() from query method. Is this understanding correct?

-Kaity

 
BalajiRanganathanBalajiRanganathan

Yes. you got it. also if you want to override the default 500 batch size you can use
setQueryOptions(int batchsize) method