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);