I want to create a managed package which supports orgs both with and without PersonAccounts enabled.

  1. Is it possible?
  2. How would I achieve this?

Is it possible?


How would I achieve this?

You need to avoid using any "hard" references to any Person Account features. For example, you'll need to check if IsPersonType is a valid field:

Boolean isPersonAccountsEnabled = sObjectType.RecordType.fields.getMap().containsKey('IsPersonType');

Since this field is only present when you have Person Accounts enabled, you have to do dynamic queries to avoid making a hard link:

RecordType[] personTypes = Database.query('SELECT Id FROM RecordType WHERE IsPersonType = true');

And so on. You can read more about Dynamic Apex in the documentation.

Finally, and I cannot stress this enough, always check the package dependencies before uploading. If you upload a version that includes dependencies to Person Accounts, you will never be able to undo it (at least, it's very hard to undo and involves Partner Support).

You may want to put all your Person Account dependencies in to an Extension Package to avoid accidentally creating dependencies, but then you'd have to have customers install two separate packages.

| improve this answer | |
  • You sir are a scholar and a gentleman – Robs Mar 19 '19 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.