I'm trying to use Custom Metadata Types
to specify some relationships between objects. So I started out by creating my Custom Metadata Type
and adding a Metadata Relationship
to an Entity Definition
.
In implementing this approach, I ran into an interesting surprise. When I tried to get an object's describe based on DeveloperName
, it didn't give me any data. If I have an object whose API Name is My_Object__c
, the DeveloperName
field contains My_Object
.
MyMetadata__mdt mapping = [
SELECT SObjectType__c, SObjectType__r.DeveloperName
FROM MyMetadata__mdt LIMIT 1
];
system.debug(mapping.SObjectType__c); // yields 01I00000000xxxx
system.debug(mapping.SObjectType__r.DeveloperName); // yields My_Object
SObjectType s = Schema.getGlobalDescribe().get(mapping.SObjectType__r.DeveloperName);
Is there no way to get it to return the API Name in a way I can pass directly to describe methods? The same problem applies when I try to query a related Field Definition
as well.