I already have an if statement checking to see if Person Accounts are enabled in the org. So the test will only run if they are enabled. However Salesforce isn't accepting it because it has Accounts with FirstName, MiddleName and LastName fields being inserted.

I am working on a Managed Package that is used in both orgs that have Person Accounts and those that do not. So it has to be the same tests running for both situations.

Is there a workaround? For example with the RecordType query I turned the query into a String so the compiler doesn't recognize the isPersonAccount as a field. But there's no INSERT keyword in SOQL. Is there another workaround so my tests can run in both types of orgs, which is a requirement?

1 Answer 1


This is what sObject.put is for. It accepts a field token or a string, so we can use a string to break any dependencies with Person Account fields. You'd have to deal with this in your main code anyways if you want to install without a Person Account dependency. You might even just make a utility/domain class to handle these requirements.

Account testAccount = new Account();
if(hasPersonAccountsEnabled()) {
  testAccount.put('FirstName', 'Brian');
  testAccount.put('MiddleName', 'M');
  testAccount.put('LastName', 'Fear');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .