---
schema_version: "1"
id: bb460ae86a37e53f38ac000001bee2198481ff4cb784c3b7dfce8af6cf522fc0
title: QueryOptionsBuilder Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Database_QueryOptionsBuilder.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 011c9c3e6369e0cc7fddab2d623ba6a5dc9654c03e6c088e777a0f627b977626
description: Contains methods to build an immutable Database.QueryOptions instance.Returns an immutable Database.QueryOptions object that reflects the current builder state.Sets the dataspace context for the query.Sets whether explicit namespace resolution is enabled for the query.Sets whether empty-string filter values are treated as meaningful rather than as null.
---
# QueryOptionsBuilder Class

Contains methods to build an immutable Database.QueryOptions instance.

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

See the Usage section of the [QueryOptions Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_class_Database_QueryOptions "Contains an immutable configuration for the SOQL SET OPTIONS clause.").

## Example

This example chains Data 360 options on the builder and runs a DLO query.

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

List<sObject> results = Database.query(
    'SELECT Id, EmailOptIn\_\_c FROM CustomerProfile\_\_dlm ' +
    'WHERE EmailOptIn\_\_c = \\'\\' SET OPTIONS :opts'
);

- **[QueryOptionsBuilder Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm#apex_Database_QueryOptionsBuilder_methods)**

## QueryOptionsBuilder Methods

The following are methods for QueryOptionsBuilder.

- **[build()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm#apex_Database_QueryOptionsBuilder_build)**  
    Returns an immutable Database.QueryOptions object that reflects the current builder state.
- **[withDataspace(value)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm#apex_Database_QueryOptionsBuilder_withDataspace)**  
    Sets the dataspace context for the query.
- **[withExplicitNamespace(bool)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm#apex_Database_QueryOptionsBuilder_withExplicitNamespace)**  
    Sets whether explicit namespace resolution is enabled for the query.
- **[withHonorEmptyStrings(bool)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptionsBuilder.htm#apex_Database_QueryOptionsBuilder_withHonorEmptyStrings)**  
    Sets whether empty-string filter values are treated as meaningful rather than as null.

### build()

Returns an immutable Database.QueryOptions object that reflects the current builder state.

#### Signature

public Database.QueryOptions build()

#### Return Value

Type: [Database.QueryOptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_QueryOptions.htm#apex_class_Database_QueryOptions "Contains an immutable configuration for the SOQL SET OPTIONS clause.")

An immutable Database.QueryOptions object that reflects the current builder state.

### withDataspace(value)

Sets the dataspace context for the query.

#### Usage

Use when querying Data 360 Data Lake Objects (DLOs). If a dataspace isn't specified for a DLO query, the query returns zero records. Valid only for DLO queries. Not supported for data model object (DMO) queries. 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.

#### Signature

public Database.QueryOptionsBuilder withDataspace(String value)

#### Parameters

dataspaceName

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. This parameter is case-sensitive. Can’t be null or empty.

#### Return Value

Type: [Database.QueryOptionsBuilder](#apex_class_Database_QueryOptionsBuilder "Contains methods to build an immutable Database.QueryOptions instance.")

This Database.QueryOptionsBuilder instance.

### withExplicitNamespace(bool)

Sets whether explicit namespace resolution is enabled for the query.

#### Usage

If true, unqualified custom field and relationship names resolve to subscriber fields, and namespace-qualified names resolve to packaged fields. Use this option in managed package Apex to avoid field-name shadowing conflicts with subscriber orgs. Setting this option to false is the same as leaving the option unset, meaning that package namespace shadowing is applied. See [Prevent Field Name Collisions in Managed SOQL Queries](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_manpkgs_package_versions.htm) in the Apex Developer Guide.

#### Signature

public Database.QueryOptionsBuilder withExplicitNamespace(Boolean bool)

#### Parameters

bool

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 to enable explicit namespace resolution, or false for namespace shadowing. Can't be null.

#### Return Value

Type: [Database.QueryOptionsBuilder](#apex_class_Database_QueryOptionsBuilder "Contains methods to build an immutable Database.QueryOptions instance.")

This Database.QueryOptionsBuilder instance.

### withHonorEmptyStrings(bool)

Sets whether empty-string filter values are treated as meaningful rather than as null.

#### Usage

Supported for Data 360 virtual entities (DLOs). Also supports simple queries for DMOs. Salesforce Platform objects don't distinguish between null and empty strings, so this option controls only Data 360 filter behavior. 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.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note.png)

#### Note

withHonorEmptyStrings(true) isn't supported for queries that include aggregate relationships, semi-joins, or foreign key relationships. Those queries throw System.QueryException at run time.

#### Signature

public Database.QueryOptionsBuilder withHonorEmptyStrings(Boolean value)

#### Parameters

bool

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 to treat null and empty strings as different values, or false to treat them the same, which is the default behavior of Salesforce Platform objects.

#### Return Value

Type: [Database.QueryOptionsBuilder](#apex_class_Database_QueryOptionsBuilder "Contains methods to build an immutable Database.QueryOptions instance.")

This Database.QueryOptionsBuilder instance.