Newer Version Available
Data Cloud In Apex
Using SOQL in Apex with Data Cloud Objects
Static SOQL is supported with Data Cloud data model objects (DMOs) as a more direct alternative to using either dynamic SOQL or ConnectAPI. Additionally, SOQL queries against DMOs using Apex Database.QueryLocator or in FOR loops is supported in API version 61.0 and later. In versions earlier than 61.0, only the first 201 records are returned. Batch Apex is blocked against DMOs when using QueryLocators, but is supported when using Iterable.
Security Considerations
You must consider field- and record-level access when using Apex with Data Cloud data model objects (DMOs). DMOs in all data spaces are accessible from Apex in system mode, even when a permission set for the data space isn’t explicitly assigned. Read-only object-level access checks are supported if the user has access to the data space. There’s currently no support for field-level security or for record-level access control. Apex features, such as WITH USER_MODE, WITH SECURITY_ENFORCED, describe calls, and Security.stripInaccessible(), can check only object-level access for DMOs.
Starting with API version 61.0, you can get information on a specific DMO using SObjectType.getDescribe(). There’s no field-level security to be enforced because all fields on DMOs that are accessed by field describes and security model checks are read only. You can’t use Schema.getGlobalDescribe() to discover exposed DMOs. Instead, use the Schema.describeSObjects(List<String>) method with the known DMO API names.
This example uses static SOQL with the UnifiedIndividual__dlm Data Cloud object.
1//Static SOQL example
2List<UnifiedIndividual__dlm> unifiedIndividuals = [
3 SELECT
4 Id,
5 ssot__FirstName__c,
6 ssot__LastName__c,
7 ssot__Email__c,
8 ssot__SkyMilesBalance__c,
9 ssot__MedallionStatus__c
10 FROM UnifiedIndividual__dlm
11 WHERE ssot__CompanyId__c = :companyId
12 ];
13
14