Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

Is there an efficient way to page through results from a SOQL query without bringing all the query results back and then discarding the majority of them?

As an example, I'd like to be able to page through the complete list of contacts showing 10 records at a time. I don't have the need to sort by any particular field.

1 Answer

0 votes
by (32.1k points)

A solution which will work with SOQL query without bringing all the query results back through the partner API is to persist the sObjects which are returned from the initial QueryResult. 

So, when a page is requested sObjects may be required from:

  • A prior QueryResult
  • The current or cached QuerResult
  • A subsequent QueryResult which can be fetched using query locator
  • Combination of three of these

If there are two or more QueryResults, an artificial QueryResult will be required to be created with all the needed records.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 14, 2020 in Salesforce by dante07 (13.1k points)
0 votes
1 answer

Browse Categories