How to check Person Account is enabled in Salesforce org or not using Apex

If Person Account is enabled then there must be a field on Account object called: isPersonAccount. We simply need to check if exists as below.

Method 1
  • Takes a bit more time and consumes heap size relatively.
  • Clean and authentic method.
public class CheckPersonAccount {
    public boolean getIsPerson(){
        return Schema.sObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' );
    }
METHOD 2
  • Reletively faster
  • But just a workaround, not sure about exception how much it will grow
public Boolean personAccountsEnabled(){
try {
        // Try to use the isPersonAccount field.
        sObject acc = new Account();
        acc.get( 'isPersonAccount' );
        // If we got here without an exception, return true.
        return true;
    }
    catch( Exception ex )
    {
        // An exception was generated trying to access the isPersonAccount field
        // so person accounts aren't enabled; return false.
        return false;
    }
}