You need to sign in to do that
Don't have an account?
abhishek_pandey1989@yahoo.com
how to get object name from id value in salesforce
Is there any method through which i can get the lookup field object name through id only that comes in that lookup field??
Thanks
Or, in one statement using ID methods
All Answers
Hi,
You can easily get the object Name from Record Id:
public string findObjectAPIName( String recordId ){
if(recordId == null)
return null;
String objectAPIName = '';
keyPrefix = recordId.substring(0,3);
for( Schema.SObjectType obj : Schema.getGlobalDescribe().Values() ){
String prefix = obj.getDescribe().getKeyPrefix();
if(prefix == keyPrefix){
objectAPIName = obj.getDescribe().getName();
break;
}
}
return objectAPIName;
}
Please let me know if u have any problem on same and if this post helps you give KUDOS by click on star at left.
Or, in one statement using ID methods
Id recordId = '005xxxxxxxxxx';
String sObjName = recordId.getSObjectType().getDescribe().getName();