---
schema_version: "1"
id: 4e772e28f98541273c24a7e4ff519f4f676ba06a7ec0c7c99e8536eb4fc5e5a7
title: Resolve Field Name Conflicts in Managed Package SOQL Queries
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/release-notes/264-0-0/rn_apex_namespace_shadowing_managed_packages.md
canonical_url: https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_namespace_shadowing_managed_packages.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e2671b7d4b9abbf3bad17f22d275ac2168ea4839ce129dbe43efe7f64f1b00ed
description: Prevent duplicate field name errors in managed Apex SOQL queries when your package fields and a subscriber’s custom fields share the same name. Set the explicitNamespace property on a Database.QueryOptions object and pass it as a bind variable in the SOQL SET OPTIONS clause. Without requiring an explicit namespace, Apex interprets both fields as belonging to your package namespace, failing the unique field name requirement enforced in API version 34.0 and later.
products:
  - Cross Cloud
release: "264"
---
# Resolve Field Name Conflicts in Managed Package SOQL Queries

Prevent duplicate field name errors in managed Apex SOQL queries when your package fields and a subscriber’s custom fields share the same name. Set the `explicitNamespace` property on a `Database.QueryOptions` object and pass it as a bind variable in the SOQL `SET OPTIONS` clause. Without requiring an explicit namespace, Apex interprets both fields as belonging to your package namespace, failing the unique field name requirement enforced in API version 34.0 and later.

**Where:** This feature is available in Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

**Why:** Field name collisions between managed packages and subscriber orgs can cause package failures. Previously, there was no mechanism for managed Apex code to explicitly control namespace resolution in SOQL. For example, if a managed package with the namespace `ExPackageNS` had an `Age__c` field and a subscriber created a custom field `Age__c`, queries for both fields simultaneously resulted in a duplicate field name error. Additionally, there was no mechanism for the managed Apex code to query for just the subscriber’s field. Now, by setting the `explicitNamespace` property as a query option, the package field resolves to `ExPackageNS__Age__c` instead. Queries without the `SET OPTIONS` clause preserve their existing behavior, so the change is backward compatible.

**How:** Create a `Database.QueryOptions` object through its builder methods, including `.withExplicitNamespace(true)`. Pass the object as a bind variable in the `SET OPTIONS` clause, and then pass the query to `Database.query()` or `Database.queryWithBinds()`.

Here’s a dynamic SOQL query created with `Database.query()`.

```java
Database.QueryOptions opts = Database.QueryOptions.builder()
    .withExplicitNamespace(true)
    .build();
List<Account> results = Database.query(
    'SELECT Id, Name, Age__c, ExPackageNS__Age__c FROM Account SET OPTIONS :opts',
    AccessLevel.USER_MODE);
```

Here’s a dynamic SOQL query created with `Database.queryWithBinds()`.

```java
Database.QueryOptions opts = Database.QueryOptions.builder()
    .withExplicitNamespace(true)
    .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);
```

#### See Also

- [_IdeaExchange_: Support Dynamic SOQL No-Shadowing Option](https://ideas.salesforce.com/s/idea/a0B8W00000Gdh9rUAB/support-dynamic-soql-no-shadowing-option)
- [_Apex Developer Guide_: Prevent Field Name Collisions in Managed SOQL Queries](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_manpkgs_dynamic_soql.htm)
- [_Apex Reference Guide_: Database.QueryOptions Class](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_Database_QueryOptions.htm)
- [_Apex Developer Guide_: Namespace Prefixes](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_classes_namespace_prefix.htm)
- [_SOQL and SOSL Reference_: SOQL SET OPTIONS Clause](https://developer.salesforce.com/docs/atlas.en-us.264.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_set_options.htm)