SqlStatement Class
Namespace
Usage
Use the static create() factories to build a statement, optionally configure the workload name with withWorkloadName(), and then either call execute() to get a synchronous SqlRowIterator or pass the statement to a SqlQueueable subclass for asynchronous execution.
Example
Build and execute a statement synchronously.
1sfsqlquery.SqlRowIterator iterator = sfsqlquery.SqlStatement.create('SELECT Id__c FROM accounts__dlm', 'default')
2 .withWorkloadName('my_workload')
3 .execute();
4
5for (sfsqlquery.Row row : iterator) {
6 System.debug(row.getString('Id__c'));
7}SqlStatement Methods
The following are methods for SqlStatement.
create(query, dataspace)
Signature
public static sfsqlquery.SqlStatement create(ConnectApi.QuerySqlInput query, String dataspace)
Parameters
- query
- Type: ConnectApi.QuerySqlInput
- Pre-built query input object that can include parameterized queries, a server-side row limit, or custom query settings.
- dataspace
- Type: String
- Name of the Data 360 data space to query against.
Return Value
Type: sfsqlquery.SqlStatement
A new SqlStatement instance configured with the provided query input and data space.
create(sql, dataspace)
Signature
public static sfsqlquery.SqlStatement create(String sql, String dataspace)
Parameters
Return Value
Type: sfsqlquery.SqlStatement
A new SqlStatement instance configured with the provided SQL and data space.
execute()
Signature
public sfsqlquery.SqlRowIterator execute()
withWorkloadName(name)
Signature
public sfsqlquery.SqlStatement withWorkloadName(String name)
Parameters
- name
- Type: String
- Custom workload name to associate with the query. Set this value to help Salesforce Customer Support assist you with debugging issues
Example
Use custom workload names to monitor and throttle different query types:
1// High-priority user-facing query
2sfsqlquery.SqlRowIterator userQuery = sfsqlquery.SqlStatement.create('SELECT * FROM accounts__dlm WHERE Region__c = \'West\'', 'default')
3 .withWorkloadName('salescloud-userdashboard')
4 .execute();
5
6// Background batch processing query
7sfsqlquery.SqlStatement batchStmt = sfsqlquery.SqlStatement.create('SELECT * FROM accounts__dlm', 'default')
8 .withWorkloadName('marketing-nightlybatch');
9System.enqueueJob(new MyBatchJob(batchStmt));