Situation:
- Managed Package
- Class is global class
- Field Named NS__Field_Name__c
Running in subscriber org code:
String fld = 'NS_Field_Name__c'; Map<String,sobjectField> flds = object__c.sobjecttype.getDescribe().fields.getMap(); Boolean test1 = flds.containsKey(fld); Boolean test2 = flds.containsKey(fld.replace('NS__',''));
In the above the result of
test1 = FALSE
test2 = TRUE
What is going on??? Why do I have to remove the namespace for the field to be found? When doing merge fields etc the name space MUST be included.....
Yes, all subscriber custom fields still show up in the field map.
To make it even worse, since subscriber (local) field show up, if the subscriber creates a field with the same name, then the Display Types are messed up because the field only shows up ONCE in the map...
Additionally this actually returns the value of the field yet the field describe says this field does not exist
objectRecord.get('NS_Field_Name__c')
How can a developer dynamically get fields identified by the subscriber from the package to get describe information if the namespace has to be removed....
(Use case, custom merge documents where the subscriber uses field API Names including namespace to display information. Display types is used for formatting)
Is this a bug???
@sfdcfox -
If I have a field of type DATE - NS__Field__c Customer creates a field of type BOLEAN Field__c
When I in the namespaced managed package get the field map the DisplayType of the field obtained using Field__c comes back as BOOLEAN instead of my namespaced type of Date.
@Daniel & @sfdcfox
It seems that it is documented so it is not a bug. However, when a package is installed in a subscriber org a field in their org with the same name will cause issues with the getMap() method since there is no namespace for their org.
Daniel was kind enough to point out the last paragraphs of the following document:
Thanks for the discussion, not really solved as the problem is still there, but it is a documented problem.....
Cheers.