Is there a way to fetch the Object API Name using the Dynamic Object label and Schema. The other way around i have done. But i need this way to get SF API Names to be sent through Rest.
I tried for Standard Case Object and its working fine, But I have a custom object called "TMC Info", Its API name is "Agency_Info__c"
But i want this value to be dynamically fetched.
Below is the code i have used and its working for standard object, but not working for custom object :
// If i give this value as 'Case' its working, but this value 'TMC Info' is showing error as Attempt to deference NULL
String myObj = 'TMC Info';
Schema.DescribeSObjectResult describe = Schema.getGlobalDescribe().get(myObj).getDescribe();
system.debug(describe.getName());
i fetched all the object api name and label, and i find the custom object "TMC Info" and its api name getting returned :
for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
{
Schema.DescribeSObjectResult objResult = o.getDescribe();
system.debug( 'Sobject: ' + objResult );
system.debug( 'Sobject API Name: ' + objResult.getName() );
system.debug( 'Sobject Label Name: ' + objResult.getLabel() );
}
Here is the picture :
Is there anything I'm missing here ?