Retrieving a single recordWhen 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 |
---|
Code Block |
---|
| 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 recordsIf 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 |
---|
Code Block |
---|
| 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 valuesIf 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 |
---|
Code Block |
---|
| 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 optionIf 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 |
---|
Code Block |
---|
| SELECT Age
FROM contact
GROUP BY Age LIMIT 2 |
or Code Block |
---|
| 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 optionYou 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 |
---|
Code Block |
---|
| 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 queriesIf 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 |
---|
Code Block |
---|
| 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 subqueriesYou 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). div#children-section.pageSection
{
display:none;
}
#main_content_override .codeContent, #main_content_override .syntaxhighlighter {
overflow:hidden!important;
}SOQL query | Data sources | |
|
---|
Code Block |
---|
| 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 | |
|