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,test@name1.com 
    TestName2,TestName22,test@name2.com

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,

  • Have you tried adding the RecordTypeId of PersonAccount record type? – CloudConnect Feb 21 '15 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. – CloudConnect Feb 21 '15 at 11:58
1

It should work:

FirstName,LastName,PersonEmail, RecordTypeId
TestName1,TestName12,test@name1.com, 012E00000000iEyAsI
TestName2,TestName22,test@name2.com, 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.

| improve this answer | |
  • @Ashwani- But we need to do without hardcoding Id's in file or apex code. Is there any way? – Murali Mohan Mandadi Feb 21 '15 at 12:58

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.