0

Iam loading a CSV file via Static Resourced to test my APEX code. I am using the following code in my test:

  List<sObject> ls1 = Test.loadData(Account.sObjectType, 'TestAccount');

CSV file look like below:

    FirstName,LastName,PersonEmail 
    TestName1,TestName12,[email protected] 
    TestName2,TestName22,[email protected]

I am getting the following error:

System.SObjectException: Business Account may not use Person Account field PersonEmail

I want to load person account test data. For this, how can i use/assign personAccount record type in csv file to overcome this exception.

Can anyone help me on this.

Thanks,

2
  • Have you tried adding the RecordTypeId of PersonAccount record type? Commented Feb 21, 2015 at 11:53
  • The error could also persist due to PersonEmail field as it is exist on Contact object. If this is the case, then remove the PersonEmail field and once the insert is done, perform an update operation with PersonEmail fields. Commented Feb 21, 2015 at 11:58

1 Answer 1

1

It should work:

FirstName,LastName,PersonEmail, RecordTypeId
TestName1,TestName12,[email protected], 012E00000000iEyAsI
TestName2,TestName22,[email protected], 012E00000000iEyAsI

Assign person type record type to insert a person Account. Otherwise record is treated as business account.

As you are static resource, you may not have scope to set recordtype id dynamically. Hardcoding will work in single instance only.

1
  • @Ashwani- But we need to do without hardcoding Id's in file or apex code. Is there any way? Commented Feb 21, 2015 at 12:58

You must log in to answer this question.

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