---
schema_version: "1"
id: 049125d187cdf0508e77b7891afe0b86fde1174e89297c5e740fc0b64b8f1743
title: sfsqlquery Namespace
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_namespace_sfsqlquery.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_sfsqlquery.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 66f3824f0c00b5243e1bfabe332579be9f5961146ea1838ba3d25b9943ee7d9e
description: Contains classes for executing SQL queries against Data 360 data spaces from Apex.
---
# sfsqlquery Namespace

Contains classes for executing SQL queries against Data 360 data spaces from Apex.

The following are the classes in the sfsqlquery namespace.

- **[QueryHandle Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_QueryHandle.htm#apex_class_sfsqlquery_QueryHandle)**  
    Tracks the runtime execution state of a Data 360 SQL query as it progresses through submission, execution, and result retrieval. Use QueryHandle to resume a previously submitted query from a saved query ID in a new SqlRowIterator or a new SqlQueueable job.
- **[Row Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_Row.htm#apex_class_sfsqlquery_Row)**  
    Wraps a single Data 360 SQL query result row and provides typed accessor methods for retrieving column values by name or by 0-based index. Row instances are produced by SqlRowIterator and SqlQueueable; you don't construct Row objects directly during normal usage.
- **[SqlQueueable Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_SqlQueueable.htm#apex_class_sfsqlquery_SqlQueueable)**  
    Abstract base class for executing long-running Data 360 SQL queries asynchronously in chained Queueable jobs. Implements Queueable and Database.AllowsCallouts. Create a concrete subclass that implements processDataChunk() to process each page of results and chainNextJob() to enqueue the next job when more data remains.
- **[SqlRowIterator Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_SqlRowIterator.htm#apex_class_sfsqlquery_SqlRowIterator)**  
    Synchronous iterator for executing Data 360 SQL queries and retrieving results row-by-row within the current transaction. Implements Iterator<Row> and Iterable<Row> for use in both for-each and while loops. The iterator is single-use; once all rows are consumed, iterating again does not restart from the beginning.
- **[SqlStatement Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_SqlStatement.htm#apex_class_sfsqlquery_SqlStatement)**  
    Encapsulates the inputs required to execute a Data 360 SQL query against a data space. Build a statement from a raw SQL string or a pre-built ConnectApi.QuerySqlInput object, and then execute synchronously with SqlRowIterator or pass it to a SqlQueueable subclass for asynchronous processing.
- **[SqlTester Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_sfsqlquery_SqlTester.htm#apex_class_sfsqlquery_SqlTester)**  
    Test utility for mocking Data 360 SQL query API responses in Apex tests. The framework automatically detects the test context via Test.isRunningTest() and returns mocked responses when configured. Call clearMocks() before each test to ensure a clean state.