Sunday, April 5, 2015

Get the Object Type by using sObject Describe call in Apex

public AccountControllerExtension(ApexPages.StandardController stdController){

// Get the record of sObject (e.g. Account, Contact etc.) by using the method "getRecord()" of StandardController
    sObject sObjectRecord = stdController.getRecord();

// Get the object type specifically by using Apex sObject Describe call
// In this case it will be Account
    String objectType = sObjectRecord.getSObjectType().getDescribe().getName();  

// Verify the Object Type
System.Debug('>>Object Type<<'+objectType);