Some time it is needed to check whether this org has person account enabled or not.

There are couple of ways we can think of,

  • Using Describe Call
boolean isPersonAccount = Schema.SObjectType.Account.fields.getMap().containsKey('isPersonAccount');

– Describe Call count against Governor limits.

  • Accessing field of Account (“isPersonAccount”)
boolean isPersonAccount = false;
try{
	Sobject accSo = new Account();
	accSo.get('isPersonAccount');

	//If this field Exists then there is Person Account Enabled in this Org. Else you will get Exception
	isPersonAccount = true;

} catch(Exception e) {
	
	isPersonAccount = false;

}

In this method exception getting generated if that field doesn’t Exist.