Using the Salesforce Object Query Language (SOQL) to Query Data in Data Cloud
Similar to how you use SOQL to query Salesforce objects, you can also use SOQL to query Data Cloud objects, such as DLOs and DMOs, with some limitations. SOQL is Salesforce's proprietary query language to query Salesforce objects. You can run SOQL in Apex classes and triggers, or by using tools such as the Developer Console's Query Editor, and SOQL Builder as part of the Salesforce Extension for Visual Studio Code.
Currently, you can’t query calculated insights or data graphs with SOQL. To query these objects, use Data Cloud object-specific APIs or SQL instead. Also, the current implementation doesn’t support aggregate queries and relationship fields. To learn about all the limitations and security considerations of querying DMOs in Apex with SOQL, see Data Cloud In Apex in the Apex Developer Guide. To learn about writing mock tests for SOQL queries on DMOs, see Mock SOQL Tests for Data Cloud Data Model Objects in the Apex Developer Guide.
SOQL is similar to SQL, but here are a few differences between the two.
- SOQL statements can execute in Apex on the Salesforce Platform, and not only using an API.
- SOQL doesn’t support the asterisk (
*
) character to retrieve all fields in theSELECT
statement. To retrieve all fields, use theFIELDS(ALL)
keyword or retrieve specific fields. - SOQL provides parent and child relationships instead of
JOIN
statements. These relationships aren't supported in the current implementation of SOQL in Data Cloud.
For the SOQL language reference, see Salesforce Object Query Language (SOQL). To learn about the use of SOQL in general with Salesforce objects, see the SOQL for Admins Trailhead module.
See Also