Some time it is needed to check whether this org has person account enabled or not.
n
There are couple of ways we can think of,
- n
- Using Describe Call
n
boolean isPersonAccount = Schema.SObjectType.Account.fields.getMap().containsKey('isPersonAccount');n
– Describe Call count against Governor limits.
- n
- Accessing field of Account (“isPersonAccount”)
n
boolean isPersonAccount = false;ntry{n Sobject accSo = new Account();n accSo.get('isPersonAccount');nn //If this field Exists then there is Person Account Enabled in this Org. Else you will get Exceptionn isPersonAccount = true;nn} catch(Exception e) {n n isPersonAccount = false;nn}
In this method exception getting generated if that field doesn’t Exist.