If shadowing occurs, Schema.SObjectType.<entity-name>.fields.getMap() only returns the local custom field
Last updated 2019-07-10 ·Reference W-5694464 ·Reported By 41 users
Given a specific entity (e.g. Account), if a manage package adds a field into the object and a field with the same name is created in this org, Schema.SObjectType.<entity-name>.fields.getMap() returns the local custom field only. This behaviour is known as shadowing as the local field is effectively hiding the field available in the managed package.
For instance, suppose 2 local custom fields CustomField1__c and CustomField2__c are created on Account, and CustomField1__c is also added by a package with namespace "FieldList". In this case, if the following Apex code is executed, only the local field "CustomField1__c" is returned, so the field available in the managed package is not available in the map.
Map<String, Schema.SObjectField> fieldList = Schema.SObjectType.Account.fields.getMap();
Contained in Summary section.
Using API V33 or V38 will be able to identify the difference between Managed package field and local custom org field.
Fixed as a versioned change in APIv34, but was not properly documented. Documentation will be updated shortly:
In API version 34.0 and later, Schema.DescribeSObjectResult on a custom SObjectType includes map keys prefixed with the namespace, even if the namespace is that of currently executing code. If you work with multiple namespaces and generate runtime describe data, make sure that your code accesses keys correctly using the namespace prefix.
Reported By (41)
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.