---
cuppy_hub: salesforce
cuppy_path: reference/official/data360/data-cloud-query-guide/guide/dc-apex-query.md
cuppy_section: docs
cuppy_doc: WB8E-F72P
cuppy_doc_uuid: f86acc32-5f9e-4231-beb5-88e8695a67cf
cuppy_permalink: https://cuppy.io/salesforce/d/WB8E-F72P
cuppy_version: 1
cuppy_updated: 2026-10-23T16:16:52.575Z
cuppy_canonical: https://cuppy.io/salesforce/docs/reference/official/data360/data-cloud-query-guide/guide/dc-apex-query
cuppy_mcp: https://cuppy.io/mcp
cuppy_body_sha256: c2eaa7a169dc88c5600c1056b2b318acc8b0c697868fbf4de4cb81c2500847f5
# cuppy_body_sha256 is over the document body ALONE, excluding both generated blocks.
---

> Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/dc-apex-query.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.

## Query Data 360 Data with Apex

Use Apex to query Data 360 data directly from your Salesforce org. Access unified customer insights and act on them immediately within your Salesforce automations.

Use the `sfsqlquery` namespace when you need an easy and intuitive way to execute queries with iterators and typed row accessors.

**When to use:** Run SQL queries on Data 360

*   Synchronous iteration over query results
*   Typed column value accessors (getString, getInteger, etc.)
*   Asynchronous processing of large datasets with SqlQueueable
*   Resume queries from saved query IDs

**Common workflows:**

The namespace provides five classes that support three primary workflows:

1.   **Execute a new query synchronously:**  
 SqlStatement → SqlRowIterator → Row

2.   **Fetch results of a previously executed query:**  
 QueryHandle → SqlRowIterator → Row

3.   **Process large datasets asynchronously:**  
 SqlQueueable → SqlRowIterator → Row

See [sfsqlquery Namespace](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_sfsqlquery.htm) in the Apex Reference.

Apex methods use the current user’s session context and permissions automatically. Ensure users have appropriate Data 360 permissions assigned through permission sets or profiles.

See [Getting Started with Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_get_started.htm) in the Apex Developer Guide.

*   **Use asynchronous patterns**: For long-running queries, implement polling logic to avoid governor limits
*   **Handle errors**: Check query status for failures and implement retry logic
*   **Test with smaller datasets**: Validate your query logic with `LIMIT` clauses before processing full datasets

Build a query with SqlStatement, execute it synchronously with SqlRowIterator, and access typed column values using the Row class. The SqlStatement.create() method builds the query, the execute() method runs it synchronously, and Row provides typed accessor methods like getString() to retrieve column values.

Resume a query from a saved query ID using QueryHandle. The QueryHandle.create() method takes a saved query ID and uses withOffset() to skip already-processed results. This is useful when you need to retrieve additional results from a previously executed query.

Process large datasets asynchronously using SqlQueueable. The custom class extends SqlQueueable and implements two key methods: processDataChunk() to handle each page of results, and chainNextJob() to automatically continue processing subsequent pages. This pattern prevents governor limit issues when working with large result sets.

For backward compatibility, the `ConnectApi.CdpQuery` class remains available as a low-level interface that directly mirrors the Connect REST API. We recommend using the `sfsqlquery` namespace for all new development.

See [ConnectApi.CdpQuery Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_ConnectAPI_CdpQuery_static_methods.htm) in the Apex Reference.

*   [Query Data 360 Data using Query API](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/data-cloud-query-api-reference/c360a-api-queryservices-overview.html) - Complete API reference
*   [Data 360 SQL Query APIs](https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/dc-sql-query-apis.html) - Overview of query API options
*   [Get Started With Data 360 SQL](https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/dc-query-section.html) - SQL syntax and examples


---
<!-- cuppy -->
You are reading one file. The same content is free over MCP at https://cuppy.io/mcp with no signup: ranked search across all 376 documents in this hub, the merged view when you work in a layer, known workarounds matched to the error you hit, and depth control so you spend tokens on what you need. Start with the `_hello` tool. How to connect: https://cuppy.io/salesforce/ Something wrong in this document? Report it with the `session feedback` tool on the same endpoint.
<!-- /cuppy -->
