Types of SOQL queries and their resulting data sources
Retrieving a single record
When you retrieve a single record, using LIMIT 1
, the resulting data sources are named using the following format:
ObjectName[.RelatedObjectName][...]|FieldName
A field on the queried object:
ObjectName|FieldName
A field on an object related to the queried object:
ObjectName.RelatedObjectName|FieldName
A field on an object related to the object related to the queried object:
ObjectName.RelatedObjectName.RelatedObjectName|FieldName
SOQL query | Data sources | Description |
---|---|---|
SELECT name, birthdate, account.name, account.owner.name FROM contact WHERE name = 'Indiana Jones' LIMIT 1 | Contact|Name Contact|Birthdate Contact.Account|Name Contact.Account.Owner|Name | Selects the contact's name and birthdate, and the associated account's name, and account owner's name for the contact called Indiana Jones. |
Retrieving multiple records
If you want to retrieve multiple records, define the maximum expected records (n) in the LIMIT
clause.
The resulting data sources are named using the following format:
ObjectName(n)[.RelatedObjectName][...]|FieldName
where n is the LIMIT
An additional data source is created to store the actual number of records you will get when running the query. This data source is named ObjectName|Record Count.
SOQL query | Data sources |
---|---|
SELECT name, birthdate, account.name, account.owner.name FROM contact WHERE name LIKE '%Jones' LIMIT 2 | Contact(1)|Name |
Retrieving aggregate values
If you want to retrieve aggregates of fields in your query, the resulting data sources are named using the following format:
ObjectName[.RelatedObjectName][...]|FieldName|AggregateName
SOQL query | Data sources |
---|---|
SELECT MIN(birthdate), AVG(age), COUNT_DISTINCT(account.name) FROM contact | Contact|Birthdate|Min |
Using GROUP BY option
If you use GROUP BY
on a set of fields, the resulting data sources are named using the same format as when you retrieve ordinary field data:
ObjectName(n)[.RelatedObjectName][...]|FieldName
SOQL query | Data sources |
---|---|
SELECT Age FROM contact GROUP BY Age LIMIT 2 or SELECT Age FROM contact WHERE name LIKE '%Jones' LIMIT 2 | Contact(1)|Age |
Retrieving field values and aggregate values using GROUP BY option
You can retrieve a mix of fields and aggregate values using GROUP BY
. You must specify the LIMIT
clause. The resulting data sources are named using the following format:
ObjectName(n)[.RelatedObjectName][...]|FieldName|AggregateName (for aggregate values)
ObjectName(n)[.RelatedObjectName][...]|FieldName (for non-aggregate values)
SOQL query | Data sources |
---|---|
SELECT MAX(amount), name, MIN(amount) FROM opportunity GROUP BY name LIMIT 2 | Opportunity(1)|Amount|Max |
Using aliases for aggregate queries
If you use aliases for your aggregate queries, the resulting data sources are named using the following format:
- When
LIMIT
is 1, ObjectName|AliasName - When
LIMIT
is more than 1, ObjectName(n)|AliasName
SOQL query | Data sources |
---|---|
SELECT MIN(owner.name) FirstOwnerNameAlphabetically, MAX(owner.name), account.name DistinctAccountName FROM opportunity GROUP BY account.name LIMIT 2 | Opportunity(1)|FirstOwnerNameAlphabetically |
Using subqueries
You can use subqueries to retrieve records together with subsets of related records. The resulting data sources are named using the following format:
ObjectName(n).SubqueryObjectName(nn)|FieldName
where n is the LIMIT
in the main query and nn is the LIMIT
in the subquery.
Additional data sources are created to store the actual number of records you will get when running the queries. These data sources are named ObjectName|Record Count and ObjectName(n).SubqueryObjectName|Record Count.
The maximum value of 10 for LIMIT
applies to the main query and each subquery. With one subquery, the maximum number of records that your complete query can return is 100 (10 x 10).
SOQL query | Data sources | |
---|---|---|
SELECT name, (SELECT name, email from account.contacts LIMIT 2) FROM account WHERE name = 'Edge Communications' LIMIT 2 | Account(1)|Name |
For general assistance, please contact Customer Support.
For help using this documentation, please send an email to docs_feedback@vonage.com. We're happy to hear from you. Your contribution helps everyone at Vonage! Please include the name of the page in your email.