Problem Description
Not being able to use both custom and managed fields in a managed package when fields share the same API name (with different namespaces). When using the DescribeSObjectResult.fields.getMap()
method, it only returns the local custom field (and not both the local custom field and the managed field).
Expected Result
Map of with both the local custom field (e.g. Description__c
) and managed field (e.g. namespace__Description__c
) returned by the DescribeSObjectResult.fields.getMap()
method.
Current Result
Only local custom fields are returned (e.g. Description__c
).
Using Salesforce API version 29.0
How to reproduce
- Create a custom object / custom field (e.g.
namespace__Object__c.namespace__Description__c
) and upload the managed package. - Install the managed package in a different organization (e.g. a developer edition organization)
- In the custom object
namespace__Object__c
add a new custom field namedDescription__c
(therefore it doesn't have a namespace) - Run the following code from the managed package
(You can/should embed it in a VF page / custom Apex controller for easy access):
Schema.DescribeSObjectResult dsr = Schema.getGlobalDescribe().get('zqu__Quote__c').getDescribe();
Map objectFields = dsr.fields.getMap();
for (String fieldName : objectFields.keySet()) {
Schema.DescribeFieldResult dfr = objectFields.get(fieldName).getDescribe();
System.debug(dfr.getName() + ' >> ' + dfr.getLabel());
}
When running in the managed package, this code will only return the customer local Description__c
custom field.
However, when running this code from the Developer Console in the local namespace, this code will return both Description__c
and zqu__Description__c
fields.