It seems to me that in my dev org at least, the keys for the map returned by Schema.GetGlobalDescribe()
do not use namespace prefixes… so does anybody know what happens when there are two objects with the same name in two different namespaces? It seems to me like there may be a bug here.
If I try and look up with Schema.GetGlobalDescribe().get('MyNamespace__MyObject__c')
then I get no hits, but if I do Schema.GetGlobalDescribe().get('MyObject__c').getDescribe().getName()
then I get the name with the prefix, so I'd expect to use that same name to perform lookups in the first case.
Best Answer
Yep! Use
SObjectType.Obj__c.Name
to resolve the namespace, for example:Static method:
Edit: dynamic method
Replace line 1:
String fqName = Type.forName(isPkg ? 'ns' : '', 'Obj__c').getName()
wherens
is set only in the packaging org, eg via Protected Custom Setting