No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
queryMore()
Retrieves the next batch of objects from a query().
Syntax
1QueryResult = connection.queryMore( QueryLocator QueryLocator);Usage
Use this call to process query() calls that retrieve a large number of records (by default, more than 500) in the result set. The query() call retrieves the first 500 records and creates a server-side cursor that is represented in the queryLocator object. The queryMore() call processes subsequent records in up to 500-record chunks, resets the server-side cursor, and returns a newly generated QueryLocator. To iterate through records in the result set, you generally call queryMore() repeatedly until all records in the result set have been processed (the Done flag is true). You can change the maximum number of records returned to up to 2,000. See Change the Batch Size in Queries in the Salesforce SOQL and SOSL Reference Guide for more information.
You can't use queryMore() if a query includes a GROUP BY clause. See GROUP BY and queryMore() in the Salesforce SOQL and SOSL Reference Guide for more information.
To connect to an external data source, Lightning Connect uses the Open Data Protocol (OData) version 2.0. To do client-side paging through the remote data set, queryMore() uses the $top and $skip system query options in OData calls. This is similar to using LIMIT and OFFSET clauses to page through a result set.
Querying a standard or custom object gathers all the IDs and creates a server-side cursor to page through. When querying external objects, each queryMore() call results in a new OData callout to the external data source. If the external data is modified between queryMore() calls, you might get an unexpected QueryResult. We recommend that you filter your queries of external data to return fewer rows than the default batch size of 500 rows. We also recommend that you avoid using queryMore() calls on external data that frequently changes.
If the primary or “driving” object for a SELECT statement is an external object, queryMore() supports only that primary object and doesn’t support subqueries.
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.
1swfobject.registerObject("clippy.codeblock-1", "9");public void queryRecords() {
2 QueryResult qResult = null;
3 try {
4 String soqlQuery = "SELECT FirstName, LastName FROM Contact";
5 qResult = connection.query(soqlQuery);
6 boolean done = false;
7 if (qResult.getSize() > 0) {
8 System.out.println("Logged-in user can see a total of "
9 + qResult.getSize() + " contact records.");
10 while (!done) {
11 SObject[] records = qResult.getRecords();
12 for (int i = 0; i < records.length; ++i) {
13 Contact con = (Contact) records[i];
14 String fName = con.getFirstName();
15 String lName = con.getLastName();
16 if (fName == null) {
17 System.out.println("Contact " + (i + 1) + ": " + lName);
18 } else {
19 System.out.println("Contact " + (i + 1) + ": " + fName
20 + " " + lName);
21 }
22 }
23 if (qResult.isDone()) {
24 done = true;
25 } else {
26 qResult = connection.queryMore(qResult.getQueryLocator());
27 }
28 }
29 } else {
30 System.out.println("No records found.");
31 }
32 System.out.println("\nQuery succesfully executed.");
33 } catch (ConnectionException ce) {
34 ce.printStackTrace();
35 }
36}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.
1swfobject.registerObject("clippy.codeblock-2", "9");public void queryRecords()
2{
3 QueryResult qResult = null;
4 try
5 {
6 String soqlQuery = "SELECT FirstName, LastName FROM Contact";
7 qResult = binding.query(soqlQuery);
8 Boolean done = false;
9 if (qResult.size > 0)
10 {
11 Console.WriteLine("Logged-in user can see a total of "
12 + qResult.size + " contact records.");
13 while (!done)
14 {
15 sObject[] records = qResult.records;
16 for (int i = 0; i < records.Length; ++i)
17 {
18 Contact con = (Contact)records[i];
19 String fName = con.FirstName;
20 String lName = con.LastName;
21 if (fName == null)
22 {
23 Console.WriteLine("Contact " + (i + 1) + ": " + lName);
24 }
25 else
26 {
27 Console.WriteLine("Contact " + (i + 1) + ": " + fName
28 + " " + lName);
29 }
30 }
31 if (qResult.done)
32 {
33 done = true;
34 }
35 else
36 {
37 qResult = binding.queryMore(qResult.queryLocator);
38 }
39 }
40 }
41 else
42 {
43 Console.WriteLine("No records found.");
44 }
45 Console.WriteLine("\nQuery succesfully executed.");
46 }
47 catch (SoapException e)
48 {
49 Console.WriteLine("An unexpected error has occurred: " +
50 e.Message + "\n" + e.StackTrace);
51 }
52}Arguments
| Name | Type | Description |
|---|---|---|
| queryLocator | QueryLocator | Represents the server-side cursor that tracks the current processing location in the query result set. |