Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

QueryOptions Class

Contains an immutable configuration for the SOQL SET OPTIONS clause.

Namespace

Database

Usage

Pass a Database.QueryOptions instance as a bind variable to the SOQL SET OPTIONS clause. Construct Database.QueryOptions instances by calling Database.QueryOptions.builder(), and then build() on the returned Database.QueryOptionsBuilder instance.

Use Database.QueryOptions with dynamic SOQL methods that support binds, including Database.query, Database.queryWithBinds, Database.countQuery, Database.countQueryWithBinds, Database.getQueryLocator, and Database.getQueryLocatorWithBinds.

Keep these considerations in mind.

  • After build(), the object is immutable. Use the get* methods to read values set on the builder.
  • Unset properties return null from their getters.
  • Only the query options that you explicitly set are applied. If not set, the platform performs the default query behavior.

Example

This example builds a Database.QueryOptions object and binds the object in a query.

1Database.QueryOptions opts = Database.QueryOptions.builder()
2    .withExplicitNamespace(true)
3    .withDataspace('default')
4    .withHonorEmptyStrings(false)
5    .build();
6
7List<Account> results = Database.queryWithBinds(
8    'SELECT Id, Name, Age__c, ExPackageNS__Age__c FROM Account SET OPTIONS :opts',
9    new Map<String, Object>{ 'opts' => opts },
10    AccessLevel.USER_MODE
11);

QueryOptions Methods

The following are methods for QueryOptions.

builder()

Returns a new Database.QueryOptionsBuilder with no options set.

Signature

public static Database.QueryOptionsBuilder builder()

Return Value

Type: Database.QueryOptionsBuilder

A new Database.QueryOptionsBuilder with no options set.

getDataspace()

Returns the dataspace name set on the builder, or null if unset.

Signature

public String getDataspace()

Return Value

Type: String

The dataspace name, or null if unset. Never returns an empty string. Use when querying Data 360 Data Lake Objects (DLOs). For more information, see SOQL SET OPTIONS in the SOQL and SOSL Reference.

getExplicitNamespace()

Returns whether explicit namespace resolution is enabled, or null if unset.

Signature

public Boolean getExplicitNamespace()

Return Value

Type: Boolean

true if explicit namespace resolution is enabled, false if it is disabled, or null if unset.

getHonorEmptyStrings()

Returns whether empty-string filter values are honored, or null if unset.

Signature

public Boolean getHonorEmptyStrings()

Return Value

Type: Boolean

true if empty-string filter values are honored, false if they aren't, or null if unset. For more information, see SOQL SET OPTIONS in the SOQL and SOSL Reference .