How to check Person Account are enabled using Apex?

    sfdcsharepoint.com

    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

    1. Using Describe Call
    2. n

    boolean isPersonAccount = Schema.SObjectType.Account.fields.getMap().containsKey('isPersonAccount');n

    – Describe Call count against Governor limits.

      n

    1. Accessing field of Account (“isPersonAccount”)
    2. 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.

    Leave a Reply

    Your email address will not be published. Required fields are marked *