SqlTester Class

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.

sfsqlquery

You provide mock column metadata and mock row data. The framework auto-generates the query submission and status responses from your mock data. Use setMockRows() to set a single page of results, or call enqueueMockRows() multiple times to simulate multi-page results. If you call cancel() in a test, any subsequent fetch against that query ID raises an exception in the mock layer, simulating production cancellation behavior.

Set up a single-page mock and test an iterator:

The following are methods for SqlTester.

Resets all mock state, including metadata, rows, and page queues. Call this at the start of each test method to ensure a clean state.

public static void clearMocks()

Type: void

Clear mocks at the start of each test:

Adds a page of mock rows to the result queue. Call this multiple times to simulate multi-page results. Each call adds one page; pages are returned in the order they were enqueued.

public static void enqueueMockRows(List<ConnectApi.QuerySqlRow> rows)

Type: void

Simulate multi-page results for SqlQueueable:

Returns true if the framework is currently executing within a test context. The framework calls this internally to decide whether to return mocked responses.

public static Boolean isRunningTest()

Type: Boolean

true if executing in a test context; false otherwise.

Sets the mock column metadata that the framework returns for all queries in the current test. Call this before executing any query.

public static void setMockMetadata(List<ConnectApi.QuerySqlMetadataItem> metadata)

Type: void

Define column metadata for mocked results:

Sets a single page of mock rows to return for the query. Use enqueueMockRows() instead when simulating multi-page results.

public static void setMockRows(List<ConnectApi.QuerySqlRow> rows)

Type: void

Set a single page of mock results: