+ Start a Discussion

Reg: Finding the objectname using object Id.



I knew object id 'a03/0' like this.

By using this id, How can i know the object name like E__c.





Ritesh AswaneyRitesh Aswaney

Hey, here's a link to a post which answers this


- the gist is

String accId = '00190000005gJcl'; // replace this id with your one

String keyCode  = accId.subString(0,3);

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType objectInstance : gd.values())
if(objectInstance.getDescribe().getKeyPrefix() == keyCode)
{//do your processing with the API name what you want
System.debug('Id is related to object: '+ objectInstance.getDescribe().getName());