Uncategorized

sObject Name from RecordId in Apex Class

When working on visualforce pages, there will be a requirement to get to know the sObject name of a record on which you are working. In lightning experience, you will get to know to know the sObject directly just like recordId. But such option is not available in classic version’s visualforce pages.

One good thing in classic version is, you will get to know the recordId in Apex class. But to get the sObject name.


Get Name of sObject.

Id a_RecordId = 'a0G0K00001CAfhHUAT';
String a_sObjectName = a_RecordId.getSObjectType().getDescribe().getName();
System.debug(a_sObjectName );

Get API name of sObject

Id a_RecordId= 'a0G0K00001CAfhHUAT';
String a_sObject_API = a_RecordId.getSObjectType();
System.debug(a_sObject_API);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s