Newer Version Available

This content describes an older version of this product. View Latest

queryMore()

Retrieves the next batch of query results.

Syntax

queryMore() requires the queryLocator parameter, the value of which is the query locator id returned in the preceding query().

Usage

Use this call to get additional results from a query() or a preceding queryMore() call that returns a large number of records. The query() and queryMore() calls can retrieve up to 2,000 records in a batch. If there are more results that can be returned in a single batch, a server-side cursor and a QueryLocator are created. The query locator is returned in QueryResult, and used in queryMore() to find the next batch of results.

The queryMore() call processes subsequent records in additional batches, resets the server-side cursor, and returns a newly generated query locator. To iterate through the records in the result set, call queryMore() repeatedly until all records in the result set have been processed and the Done flag is true.

You can't use queryMore() if a query includes a GROUP BY clause. See Salesforce SOQL and SOSL Reference Guide: GROUP BY for more information.

When querying external objects, Salesforce Connect accesses the external data in real time via Web service callouts, and each queryMore() call results in a callout. The batch boundaries and page sizes depend on your adapter and how you set up the external data source.

We recommend:
  • Avoid paging by filtering your queries of external objects to return fewer rows than the batch size, which by default is 2,000 rows. Remember, obtaining each batch requires a queryMore() call, which results in a Web service callout.
  • If the external data frequently changes, avoid using queryMore() calls. If the external data is modified between queryMore() calls, you can get an unexpected QueryResult.

If the primary object for a SELECT statement is an external object, queryMore() supports only that primary object and doesn’t support subqueries.

See Salesforce Help: Client-driven and Server-driven Paging for Salesforce Connect—OData 2.0 and 4.0 Adapters.

Sample Code—Java

This sample executes a query that fetches the first names and last names of all contacts. It calls query() with the query string to get the first batch of records. It then calls queryMore() in a loop to get subsequent batches of records until no records are returned. It writes the first and last names of the contacts queried to the console.

Sample Code—C#

This sample executes a query that fetches the first names and last names of all contacts. It calls query() with the query string to get the first batch of records. It then calls queryMore() in a loop to get subsequent batches of records until no records are returned. It writes the first and last names of the contacts queried to the console.

Arguments

Name Type Description
queryLocator QueryLocator Points to a server-side cursor in the database. Tracks the current processing location in the query results set and indicates the location of additional results.

A query locator is a specialized string, similar to an ID, and is 18 characters long and begins with the prefix 0r8. Required for retrieving subsequent sets of objects from query results, if needed.

Response

QueryResult