---
schema_version: "1"
id: 86e8bd4f6e97efdfb35850baaad83910a0f21419f82095c67adc5d6af1307c45
title: QueryOptions Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Database_QueryOptions.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 910eb654c0664ddd8155fdb81c6d1bcafb9cfbc2f31184e175a228dd0d608be8
description: Contains an immutable configuration for the SOQL SET OPTIONS clause.Returns a new Database.QueryOptionsBuilder with no options set.Returns the dataspace name set on the builder, or null if unset.Returns whether explicit namespace resolution is enabled, or null if unset.Returns whether empty-string filter values are honored, or null if unset.
---
# QueryOptions Class

Contains an immutable configuration for the SOQL SET OPTIONS clause.

## Namespace

[Database](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Database.htm "The Database namespace provides classes used with DML operations.")

## 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.

Database.QueryOptions opts = Database.QueryOptions.builder()
    .withExplicitNamespace(true)
    .withDataspace('default')
    .withHonorEmptyStrings(false)
    .build();

List<Account> results = Database.queryWithBinds(
    'SELECT Id, Name, Age\_\_c, ExPackageNS\_\_Age\_\_c FROM Account SET OPTIONS :opts',
    new Map<String, Object\>{ 'opts' => opts },
    AccessLevel.USER\_MODE
);

- **[QueryOptions Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_Database_QueryOptions_methods)**

## QueryOptions Methods

The following are methods for QueryOptions.

- **[builder()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_Database_QueryOptions_builder)**  
    Returns a new Database.QueryOptionsBuilder with no options set.
- **[getDataspace()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_Database_QueryOptions_getDataspace)**  
    Returns the dataspace name set on the builder, or null if unset.
- **[getExplicitNamespace()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_Database_QueryOptions_getExplicitNamespace)**  
    Returns whether explicit namespace resolution is enabled, or null if unset.
- **[getHonorEmptyStrings()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_Database_QueryOptions_getHonorEmptyStrings)**  
    Returns whether empty-string filter values are honored, or null if unset.

### builder()

Returns a new Database.QueryOptionsBuilder with no options set.

#### Signature

public static Database.QueryOptionsBuilder builder()

#### Return Value

Type: [Database.QueryOptionsBuilder](#apex_Database_QueryOptions_builder "Returns a new Database.QueryOptionsBuilder with no options set.")

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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

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](https://developer.salesforce.com/docs/atlas.en-us.264.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_set_options.htm "HTML (New Window)") 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

true if empty-string filter values are honored, false if they aren't, or null if unset. For more information, see [SOQL SET OPTIONS](https://developer.salesforce.com/docs/atlas.en-us.264.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_set_options.htm "HTML (New Window)") in the SOQL and SOSL Reference .