We all know that salesforce gives us the facility to create record types. The layout of a certain record page changes with respect to its record type. But do you know that there is one record type which merges account and contact sObjects? This feature of Salesforce is called Person Account. When person account is enabled in any org we get a few new fields in that org and a brand new record type which is called the Person Account record type. A person account cannot even have child contacts. This changes functionality significantly. Now you must be thinking if we can determine whether any org has person account enabled? Yes, and I will show how to do it.
Apex Code
public class CheckPersonAccount { public boolean getIsPerson(){ return Schema.sObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' ); } }
In the above class, I have used the Schema Class which is used to directly reference the sObject class of your Org. Through the Schema class, I have got a map of all the fields in the account sObject. After that I have checked if it has an isPersonAccount field. This field is one of the fields added to any org if person account is enabled. So in short if the org has this field then person account is enabled in your org, else it is not.
Visualforce Code
<apex:page controller="checkPersonAccount"> <apex:outputText rendered="{!isPerson}">Person Account is Enabled</apex:outputText> <apex:outputText rendered="{!NOT(isPerson)}">Person Account is Not Enabled</apex:outputText> </apex:page>
Here we are displaying whether the org has Person Acc. enabled or not. If it is not enabled then the second outputtext will be shown, else the first will be shown.
Output
Support
That’s all about how to determine whether we can check if any org has person acc. enabled from APEX, for any further queries feel free to contact us at:
https://wedgecommerce.com/contact-us/
Or let us know your views about this blog in the comments section below.