Types of SOQL queries and their resulting data sources

In this page

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 queryData sourcesDescription
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 queryData sources
SELECT name, birthdate, account.name, account.owner.name
FROM contact
WHERE name LIKE '%Jones'
LIMIT 2

Contact(1)|Name
Contact(1)|Birthdate
Contact(1).Account|Name
Contact(1).Account.Owner|Name
Contact(2)|Name
Contact(2)|Birthdate
Contact(2).Account|Name
Contact(2).Account.Owner|Name
Contact|Record Count

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 queryData sources
SELECT MIN(birthdate), AVG(age), COUNT_DISTINCT(account.name)
FROM contact

Contact|Birthdate|Min
Contact|Age|Avg
Contact.Account|Name|Count Distinct

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 queryData sources
SELECT Age
FROM contact
GROUP BY Age LIMIT 2

or

SELECT Age
FROM contact
WHERE name LIKE '%Jones' LIMIT 2

Contact(1)|Age
Contact(2)|Age
Contact|Record Count

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 queryData sources
SELECT MAX(amount), name, MIN(amount) 
FROM opportunity
GROUP BY name
LIMIT 2

Opportunity(1)|Amount|Max
Opportunity(1)|Name
Opportunity(1)|Amount|Min
Opportunity(2)|Amount|Max
Opportunity(2)|Name
Opportunity(2)|Amount|Min
Opportunity|Record Count

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 queryData sources
SELECT
	MIN(owner.name) FirstOwnerNameAlphabetically,
	MAX(owner.name),
	account.name DistinctAccountName
FROM opportunity
GROUP BY account.name
LIMIT 2

Opportunity(1)|FirstOwnerNameAlphabetically
Opportunity(1).Owner|Name|Max
Opportunity(1)|DistinctAccountName
Opportunity(2)|FirstOwnerNameAlphabetically
Opportunity(2).Owner|Name|Max
Opportunity(2)|DistinctAccountName
Opportunity|Record Count

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 queryData sources
SELECT
	name,
	(SELECT name, email from account.contacts LIMIT 2)
FROM account
WHERE name = 'Edge Communications'
LIMIT 2

Account(1)|Name
Account(1).Contacts(1)|Name
Account(1).Contacts(1)|Email
Account(1).Contacts(2)|Name
Account(1).Contacts(2)|Email
Account(2)|Name
Account(2).Contacts(1)|Name
Account(2).Contacts(1)|Email
Account(2).Contacts(2)|Name
Account(2).Contacts(2)|Email
Account|RecordCount, Account(1).Contacts|RecordCount
Account(2).Contacts|RecordCount


Support and documentation feedback

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.