Activity › Forums › Salesforce® Discussions › What’s the best way to check if person accounts are enabled via Salesforce Apex Code?
Tagged: Account Object, HTTP GET, isPersonAccount, Metadata in Salesforce, Person Accounts, Property in Salesforce, Salesforce Accounts, Salesforce Apex Code, Salesforce Bundle, Salesforce Certification, Salesforce sObject
-
What’s the best way to check if person accounts are enabled via Salesforce Apex Code?
Posted by shradha jain on July 27, 2018 at 9:29 AMWhat’s the best way to check if person accounts are enabled via Salesforce Apex Code?
Parul replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Shradha,
Using isPersonAccount property on an Account and catch any exception that occurs if that property is missing. If an exception is generated then person accounts are disabled. Otherwise they’re enabled. To avoid making person accounts required for the package you assign the Account object to an sObject and use sObject.get( ‘isPersonAccount’ ) rather than accessing that property directly on the Account object.
Thanks.
- [adinserter block='9']
-
Hi,
Try to access the isPersonAccount property on an Account and catch any exception that occurs if that property is missing. If an exception is generated then person accounts are disabled. Otherwise they’re enabled. To avoid making person accounts required for the package you assign the Account object to an sObject and use sObject.get( ‘isPersonAccount’ ) rather than accessing that property directly on the Account object.
This method takes ~3.5ms and negligible heap space in my testing.
Hope this helps.
-
Hi
Method 1:
Endeavor to get to the is Person Account property on an Account and catch any exemption that happens if that property is absent. In the event that a special case is produced then individual records are handicapped. Else, they’re empowered. To abstain from making individual records required for the (Salesforce Certification Training) bundle you allocate the Account protest a subject and utilize subject. Get (‘is Person Account’) as opposed to getting to that property straightforwardly on the Account question.
This method takes ~3.5ms and negligible heap space in my testing.Method 2:
Use the account meta-data to check to see if the isPersonAccount field exists. I think this is a more elegant method but it executes a describe call which counts towards your governor limits. It’s also slightly slower and uses a lot more heap space.Thanks
Log In to reply.