+ Start a Discussion

Is Salesforce Org Enabled for Person Account

I need an Apex function which determines if the Salesforce Org where is runs is enabled for the Person Account Type.


Has someone any ideas how to do this.





nope by default person account is not enabled to org..you need to request salesforce to activate person account first... then you can use recordtype object to check whether your org is enabled with person account or not

Dirk GronertDirk Gronert

You can retrieve the metadata of the account object and check for standard PersonAccount fields ...


Map<String, Schema.SObjectField> accFieldMap = Schema.sObjectType.Account.fields.getMap();


if(accFieldmap.get('IsPersonAccount') != null){

   // here we go ... this or has PersonAccount enabled


   // here we go ... this or has not PersonAccount enabled







I know this is a rather old message but I've found that it's approximately twice as fast to try to access the person account field via an sObject and then catch the exception if the field is missing.  It also avoid using a describe call since those are limited by the governor, though the limit is pretty high now at 100.


From my testing this method takes ~3.5ms whereas using a describe call to test this takes ~7ms.  This method also uses a lot less memory: ~5k for this version vs. ~100k for the describe version.


Here's the code I'm using:


// Test to see if person accounts are enabled.
private static Boolean personAccountsEnabled()
		// Try to use the isPersonAccount field.
		sObject testObject = new Account();
		testObject.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;


Here's an optimized version of the describe call method to check for person accounts:



// Check to see if person accounts are enabled.
static Boolean personAccountsEnabled()
	// Describe the Account object to get a map of all fields
	// then check to see if the map contains the field 'isPersonAccount'
	return Schema.sObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' );