{"id":2570,"date":"2026-11-09T09:00:00","date_gmt":"2026-11-09T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/"},"modified":"2026-11-15T22:01:06","modified_gmt":"2026-11-15T16:31:06","slug":"data-cloud-in-apex","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/","title":{"rendered":"Data Cloud in Apex Queries and Objects Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Data Cloud in Apex looks like ordinary SOQL and behaves like nothing of the sort. The objects live outside your org, a static query against one counts as a callout, security works differently, and every query spends credits from your subscription.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">None of that makes Data Cloud in Apex a bad tool. It makes it a tool worth understanding before a trigger starts querying it two hundred times in a loop.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-1-1024x640.png\" alt=\"Data Cloud in Apex diagram showing the query leaving the org and returning rows\" class=\"wp-image-2568\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: The query leaving the org is the fact that explains almost every rule that follows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Data Cloud in Apex Object Types<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Suffix<\/th><th>What it is<\/th><\/tr><\/thead><tbody><tr><td>__dlm<\/td><td>A data model object, the mapped and shaped data<\/td><\/tr><tr><td>__dll<\/td><td>A data lake object, closer to the raw ingested data<\/td><\/tr><tr><td>__cio<\/td><td>A calculated insight object, holding computed measures<\/td><\/tr><tr><td>Unified objects<\/td><td>Data model objects holding the resolved single profile<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With Data Cloud in Apex the object you query most is a data model object, and the most familiar example is the unified individual.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;UnifiedIndividual__dlm&gt; matches = [\n    SELECT Id, ssot__FirstName__c, ssot__LastName__c\n    FROM UnifiedIndividual__dlm\n    WHERE ssot__LastName__c = :surname\n    LIMIT 50\n];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Static SOQL is the simplest Data Cloud in Apex route, and it is the preferred one over dynamic SOQL or the Connect API when a plain read is all you need.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Rules That Catch People<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Rule<\/th><th>What it means<\/th><\/tr><\/thead><tbody><tr><td>A static query acts as a callout<\/td><td>Callout restrictions apply, including after a DML statement<\/td><\/tr><tr><td>Query locators and for loops need API 61.0 or later<\/td><td>Earlier versions return only the first 201 rows<\/td><\/tr><tr><td>Batch Apex with a query locator is blocked<\/td><td>Use the iterable form of batch instead<\/td><\/tr><tr><td>Queries consume data services credits<\/td><td>A loop that queries per record is expensive<\/td><\/tr><tr><td>Relationship traversal across these objects is limited<\/td><td>You cannot replace a SQL join with dot notation<\/td><\/tr><tr><td>Aggregates work on data model objects only<\/td><td>Not on data lake objects<\/td><\/tr><tr><td>Calculated insight objects cannot be queried this way<\/td><td>Use the Connect API route<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The silent 201 row truncation is the worst of these, because a class created on an older API version returns a short list and reports no problem at all. Checking the class API version is the first thing to do when a count looks wrong.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Data Cloud in Apex Security Behaves Differently<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the part to read twice before a security review.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Expectation<\/th><th>Reality for these objects<\/th><\/tr><\/thead><tbody><tr><td>Sharing rules apply<\/td><td>They do not, in the way they do for CRM records<\/td><\/tr><tr><td>A permission set gates access<\/td><td>Data model objects are reachable from Apex in system mode regardless<\/td><\/tr><tr><td>USER_MODE enforces field access<\/td><td>It can check object level access only<\/td><\/tr><tr><td>stripInaccessible filters fields<\/td><td>Again, object level only<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So the filter in your query is the control, not the platform. If a component should only show one person&#8217;s profile, the query has to constrain it, and a code review has to check that it does. The post on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-crud-and-fls-user-mode\/\">CRUD and field level security<\/a> covers how this differs from ordinary objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One more practical note. A global describe does not list these objects, so use a describe call with the known API names instead of looking for them in a loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Schema.DescribeSObjectResult&gt; described =\n    Schema.describeSObjects(new List&lt;String&gt;{ 'UnifiedIndividual__dlm' });<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">The Connect API Route for Data Cloud in Apex<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-2-1024x640.png\" alt=\"Data Cloud in Apex comparison diagram of SOQL and the SQL query route\" class=\"wp-image-2569\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: Simple reads go through SOQL, and anything analytical goes through SQL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When SOQL runs out for Data Cloud in Apex, the <code>ConnectApi.CdpQuery<\/code> class runs SQL across data model, lake, unified and linked objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ConnectApi.CdpQueryInput input = new ConnectApi.CdpQueryInput();\ninput.sql = 'SELECT ssot__FirstName__c, ssot__LastName__c '\n    + 'FROM UnifiedIndividual__dlm LIMIT 100';\n\nConnectApi.CdpQueryOutputV2 output = ConnectApi.CdpQuery.queryAnsiSqlV2(input);<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>What it does<\/th><\/tr><\/thead><tbody><tr><td>queryAnsiSqlV2<\/td><td>Runs SQL and returns up to a documented payload size<\/td><\/tr><tr><td>nextBatchAnsiSqlV2<\/td><td>Fetches the next batch, using the next batch id<\/td><\/tr><tr><td>queryANSISql<\/td><td>The older method, returning up to a few thousand rows<\/td><\/tr><tr><td>queryProfileApi<\/td><td>Queries a profile object with filters and a search key<\/td><\/tr><tr><td>getProfileMetadata<\/td><td>Returns fields, types and indexes for a profile object<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The batch id is how you page. The first call returns rows and an id, and you pass that id back for the next batch, for a limited period afterwards. That is a different shape from a SOQL query locator, so a client written for one does not translate to the other.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Newer releases keep adding dedicated Apex support for Data Cloud SQL, so check the current developer guide rather than an older article before you settle on a route.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Keeping the Credit Cost Down<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data Cloud in Apex credits are the part that turns a working feature into an uncomfortable conversation.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Habit<\/th><th>Why it saves credits<\/th><\/tr><\/thead><tbody><tr><td>Query once per transaction, never per record<\/td><td>A loop multiplies the cost by the record count<\/td><\/tr><tr><td>Select only the fields you use<\/td><td>Smaller results cost less to move<\/td><\/tr><tr><td>Cache a result on the record when it is stable<\/td><td>A profile summary rarely changes within a day<\/td><\/tr><tr><td>Keep queries out of triggers<\/td><td>A bulk load would query on every save<\/td><\/tr><tr><td>Use a scheduled job for aggregates<\/td><td>One query a night rather than one per page view<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ProfileSummaryBatch implements Database.Batchable&lt;SObject&gt;, Iterable&lt;SObject&gt; {\n    \/\/ the iterable form, since a query locator is blocked for these objects\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Data Cloud in Apex Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data Cloud in Apex cost us real money before we fixed it. Bright Path Tutors unified student records from the portal, the finance system and Salesforce. A component on the contact page showed the unified profile.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first version queried on every page load.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem<\/th><th>What it cost<\/th><\/tr><\/thead><tbody><tr><td>A query per page view<\/td><td>Credits consumed all day<\/td><\/tr><tr><td>A trigger that also queried<\/td><td>Bulk loads multiplied it<\/td><\/tr><tr><td>An old class API version<\/td><td>Only the first 201 rows, silently<\/td><\/tr><tr><td>Sharing assumed to apply<\/td><td>A review finding, since it does not<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We changed four things and left the feature itself alone.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Change<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>A nightly job writing a summary field<\/td><td>Credit use fell sharply<\/td><\/tr><tr><td>The component reads the summary field<\/td><td>Instant page load<\/td><\/tr><tr><td>The class moved to a current API version<\/td><td>Full result sets<\/td><\/tr><tr><td>The query constrained by contact<\/td><td>The review finding cleared<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Measure<\/th><th>Before<\/th><th>After<\/th><\/tr><\/thead><tbody><tr><td>Data Cloud queries per day<\/td><td>Thousands<\/td><td>Around one per contact<\/td><\/tr><tr><td>Contact page load<\/td><td>Two seconds<\/td><td>Immediate<\/td><\/tr><tr><td>Rows the old query missed<\/td><td>Everything past 201<\/td><td>None<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The silent truncation was the most dangerous Data Cloud in Apex problem of the four, because the feature looked like it worked. A student with a long history simply showed an incomplete picture.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing Data Cloud in Apex Without Real Records<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data Cloud in Apex cannot insert a row into a data model object in a test, which is a genuine problem for coverage. Apex provides stub methods that let a test return prepared rows for a data model object query, so the test exercises your handling rather than the data store.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Approach<\/th><th>What it gives you<\/th><\/tr><\/thead><tbody><tr><td>SOQL stub methods for these objects<\/td><td>Prepared rows a test can assert on<\/td><\/tr><tr><td>A thin service class around the query<\/td><td>Somewhere to stub with the Apex Stub API<\/td><\/tr><tr><td>An assertion on your mapping logic<\/td><td>The part that actually breaks<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Wrapping Data Cloud in Apex behind a small service is worth it on its own, and the <a href=\"https:\/\/swapnilzambare.com\/blog\/crm-analytics-basics-for-admins\/\">Data Cloud basics for admins<\/a> post covers the reporting side, because that service becomes the one place where the credit cost lives. The post on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-stub-api-mocking\/\">the Apex Stub API<\/a> covers stubbing that service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Data Cloud in Apex<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Mistake<\/th><th>What you see<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>An old class API version<\/td><td>Only the first 201 rows, with no error<\/td><td>Move the class to a current version<\/td><\/tr><tr><td>A query inside a loop<\/td><td>Credits consumed and slow transactions<\/td><td>Query once and map in memory<\/td><\/tr><tr><td>A query in a trigger<\/td><td>Bulk loads multiply the cost<\/td><td>Move it to an asynchronous job<\/td><\/tr><tr><td>Assuming sharing applies<\/td><td>A security finding<\/td><td>Constrain the query yourself<\/td><\/tr><tr><td>Relying on USER_MODE for field access<\/td><td>Field level gaps<\/td><td>Remember it checks object level only<\/td><\/tr><tr><td>A query locator in batch Apex<\/td><td>A blocked job<\/td><td>Use the iterable form<\/td><\/tr><tr><td>Looking for the objects in a global describe<\/td><td>Nothing found<\/td><td>Describe the known API names<\/td><\/tr><tr><td>Expecting dot notation joins<\/td><td>Query errors<\/td><td>Use the SQL route for joins<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Data Cloud in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Treat every query as a callout, because that is what it is<\/li>\n\n<li>Keep every query behind one small service class<\/li>\n\n<li>Query once per transaction and map results in memory<\/li>\n\n<li>Select only the fields the feature uses<\/li>\n\n<li>Store a stable summary on a record rather than querying on each view<\/li>\n\n<li>Keep queries out of triggers entirely<\/li>\n\n<li>Constrain every query by the person or record in scope<\/li>\n\n<li>Use the SQL route when you need joins or analytical shapes<\/li>\n\n<li>Keep classes on a current API version and say why in a comment<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Data Cloud in Apex Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What suffix marks a data model object?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A double l m suffix on the API name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What is a data lake object?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The object closer to the raw ingested data, before mapping, with its own suffix.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What is a calculated insight object?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An object holding computed measures, which SOQL cannot query.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What is the unified individual?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A data model object holding the resolved single profile for a person.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: Why is a static query against one treated as a callout?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the data lives outside your org, so the query leaves it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What follows from that?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Callout restrictions apply, including the rule about callouts after DML in a transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What happens on an older class API version?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Only the first 201 rows are returned, with no error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: Which API version changed that?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Support for query locators and for loops arrived in version 61.0.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: Can batch Apex use a query locator on these objects?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Use the iterable form of the batch interface instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: What does a query cost?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Data services credits from your subscription, so volume matters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: Do sharing rules apply?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not in the way they do for CRM records, so the query filter is the control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: What can USER_MODE enforce for these objects?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Object level access only, not field level.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Does stripInaccessible help?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Only at the object level, for the same reason.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: Why does a global describe not show them?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They are not listed that way, so describe the known API names directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Can you traverse relationships with dot notation?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not in the way ordinary SOQL allows, which is why joins go through the SQL route.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Which class runs SQL from Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The CdpQuery class in the Connect API namespace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Which method is the current SQL entry point?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ANSI SQL method that returns a batch of data plus a next batch id.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do you page through SQL results?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pass the next batch id back on a following call, within the allowed window.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: What does queryProfileApi do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Queries a profile object with filters and a search key, without writing SQL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: What does getProfileMetadata return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The fields, data types and indexes available for a profile object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Where do aggregates work?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On data model objects, not on data lake objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How do you test code that queries these objects?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the SOQL stub methods for them, and by keeping the query behind a service you can stub.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: Why can you not just insert test rows?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The data is not stored in your org, so there is nothing to insert into.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: What is the single biggest cost mistake?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Querying per record or per page view instead of once, or on a schedule.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Scenario: a list looks short but nothing failed. What do you check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The class API version, since an old one truncates at 201 rows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: Scenario: credits spiked after a data load. What happened?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A trigger is querying Data Cloud, so every saved record caused a query.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: Scenario: a reviewer says a component leaks profiles. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The query is not constrained, and sharing is not doing the work you assumed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Scenario: a batch job will not start. What is wrong?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It uses a query locator, which is blocked for these objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: Scenario: you need a join across two objects. What now?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the SQL route through the Connect API rather than SOQL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q30: What is the one habit that keeps this safe and affordable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One service class, one query per transaction, a constrained filter, and a summary stored for reuse.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_ConnectAPI_CdpQuery_static_methods.htm\" target=\"_blank\" rel=\"noopener noreferrer\">CdpQuery Class in the Apex Reference<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.soql_sosl.meta\/soql_sosl\/\" target=\"_blank\" rel=\"noopener noreferrer\">SOQL and SOSL Reference<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Next<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, read <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-offline-mobile-sdk\/\">LWC Offline and the Salesforce Mobile SDK Explained<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.<\/p>\n","protected":false},"author":1,"featured_media":2567,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96,240],"tags":[98,88,40,26],"swapz_series":[],"class_list":["post-2570","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","category-soql-data","tag-apex","tag-data-360","tag-data-model","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Data Cloud in Apex with Queries and Objects<\/title>\n<meta name=\"description\" content=\"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Cloud in Apex with Queries and Objects\" \/>\n<meta property=\"og:description\" content=\"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-09T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T16:31:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Data Cloud in Apex Queries and Objects Explained\",\"datePublished\":\"2026-11-09T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:31:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/\"},\"wordCount\":2014,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/data-cloud-in-apex-featured.png\",\"keywords\":[\"Apex\",\"Data 360\",\"Data Model\",\"Intermediate\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\",\"SOQL and Data\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/\",\"name\":\"Data Cloud in Apex with Queries and Objects\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/data-cloud-in-apex-featured.png\",\"datePublished\":\"2026-11-09T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:31:06+00:00\",\"description\":\"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/data-cloud-in-apex-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/data-cloud-in-apex-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Data Cloud in Apex featured image showing a query crossing from an org into a separate data store\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/data-cloud-in-apex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Cloud in Apex Queries and Objects Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Cloud in Apex with Queries and Objects","description":"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/","og_locale":"en_US","og_type":"article","og_title":"Data Cloud in Apex with Queries and Objects","og_description":"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.","og_url":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-11-09T03:30:00+00:00","article_modified_time":"2026-11-15T16:31:06+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Data Cloud in Apex Queries and Objects Explained","datePublished":"2026-11-09T03:30:00+00:00","dateModified":"2026-11-15T16:31:06+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/"},"wordCount":2014,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png","keywords":["Apex","Data 360","Data Model","Intermediate"],"articleSection":["Salesforce","Salesforce Developer","SOQL and Data"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/","url":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/","name":"Data Cloud in Apex with Queries and Objects","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png","datePublished":"2026-11-09T03:30:00+00:00","dateModified":"2026-11-15T16:31:06+00:00","description":"Data Cloud in Apex means SOQL that leaves your org, credits that get spent and security that behaves differently. Learn the objects and the traps.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/data-cloud-in-apex-featured.png","width":2400,"height":1260,"caption":"Data Cloud in Apex featured image showing a query crossing from an org into a separate data store"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/data-cloud-in-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Data Cloud in Apex Queries and Objects Explained"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=2570"}],"version-history":[{"count":2,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2570\/revisions"}],"predecessor-version":[{"id":3416,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2570\/revisions\/3416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2567"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2570"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}