Newer Version Available
Understanding Query Results
Query results are returned as nested objects. The primary or “driving”
object of the main SELECT statement in a SOQL query contains
query results of subqueries.
For example, you can construct a query using either parent-to-child or child-to-parent syntax:
- Child-to-parent:
This query returns one query result (assuming there were not too many returned records), with a row for every contact that met the WHERE clause criteria.
- Parent-to-child:
This query returns a set of accounts, and within each account, a query result set of Contact fields containing the contact information from the subquery.
Subquery results are like regular query results in that you might need to use queryMore() to retrieve all the records if there are many children. For example, if you issue a query
on accounts that includes a subquery, your client application must handle results from the
subquery as well:
- Perform the query on Account.
- Iterate over the account QueryResult with queryMore().
- For each account object, retrieve the contacts QueryResult.
- Iterate over the child contacts, using queryMore() on each contact's QueryResult.
The following sample illustrates how to process subquery results: