Newer Version Available

This content describes an older version of this product. View Latest

Supported SOQL Commands

Async SOQL supports a subset of commands in the SOQL language. The subset includes the most common commands that are relevant to key use cases.

For details of any command, refer to the SOQL documentation.

Note

WHERE

Comparison operators
1=, !=, <, <=, >, >=, LIKE
Logical operators
1AND, OR
Date formats
1YYYY-MM-DD, YYYY-MM-DDThh:mm:ss-hh:mm
Example
1SELECT AnnualRevenue
2FROM Account
3WHERE NumberOfEmployees > 1000 AND ShippingState = ‘CA’

Date Functions

Date functions in Async SOQL queries allow you to group or filter data by time periods, such as day or hour.

Method Details
DAY_ONLY() Returns a date representing the day portion of a dateTime field.
HOUR_IN_DAY() Returns a number representing the hour in the day for a dateTime field.
CALENDAR_MONTH() Returns a number representing the month for a dateTime field.
CALENDAR_YEAR() Returns the year for a dateTime field.
Example
1SELECT DAY_ONLY(date__c), HOUR_IN_DAY(date__c), COUNT(Id)
2FROM FieldHistoryArchive
3GROUP BY DAY_ONLY(date__c), HOUR_IN_DAY(date__c)

Aggregate Functions

1AVG(field), COUNT(field), COUNT_DISTINCT(field), SUM(field), MIN(field), MAX(field)

MIN() and MAX() do not support picklists.

Note

Example
1SELECT COUNT(field)
2FROM FieldHistoryArchive

HAVING

Use this command to filter results from aggregate functions.

Example
1SELECT LeadSource, COUNT(Name)
2FROM Lead
3GROUP BY LeadSource HAVING COUNT (Name) > 100

GROUP BY

Use this option to avoid iterating through individual query results. Specify a group of records instead of processing many individual records.

Example
1SELECT COUNT(Id) count, CreatedById createdBy
2FROM FieldHistoryArchive
3GROUP BY CreatedById

Relationship Queries

Single-level child-to-parent relationships are supported using dot notation. Use these queries with the SELECT, WHERE, and GROUP BY clauses.

Example
1SELECT Account.ShippingState s, COUNT(Id) c
2FROM Contact
3GROUP BY Account.ShippingState

Using Aliases with Aggregates

Examples
1{"query":"SELECT COUNT(Id) c, EventTime t FROM LoginEvent group by EventTime",
2 "targetObject":"QueryEvents__c",
3 "targetFieldMap":{"c":"Count__c", "t" : "EventTime__c"}
4}
1{"query":"SELECT COUNT(Id), EventTime FROM LoginEvent group by EventTime",          
2 "targetObject":"QueryEvents__c",
3 "targetFieldMap":{"expr0":"Count__c","EventTime" : "EventTime__c"}
4}
1{"query":"SELECT COUNT(Id ) c , firstField__c f FROM SourceObject__c", 
2 "targetObject":"TargetObject__c",
3 "targetFieldMap":{"c":"countTarget__c","f":"secondFieldTarget__c"}
4}