I want to create a managed package which supports orgs both with and without
- Is it possible?
- 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.