0

I am trying to export data in csv from one sandbox and trying to load the same data into Test class using loadData method. Currently , I am struggling in creating RecordType within Test class

For example, I do have account data in csv format mentioned below

"Id","PersonEmail","LastName","RecordTypeId"
"0011C00002YT983QAD","vc404@gmail.com","Chahal","01215000001RATXAA4"

Now when I run above data using below code it throws Validation Errors While Saving Record(s)

    List<sObject> accountList = Test.loadData(Account.getSObjectType(), 'AccountSample');

I have covered all the required fields in CSV data but it looks like RecordTypeId is creating an issue as Test Class does not know about the RecordType data.

So I don't know how would I load RecordType data in Test Class using loadData itself. I am aware that using following code I can get the Id of RecordType but how would I add those into my CSV file.

    Id RecordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
  • Loaddata inserts the data and you don't need an ID in the insert call. So you can remove the ID column. Also, can you put the complete error message, there should be something after that Errors while saving records. – manjit5190 Apr 9 at 10:18
  • Well i just realized that the data that I am importing has to be Person Account but not sure how to load that in test class – Hunt Apr 9 at 10:34

Your Answer

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

Browse other questions tagged or ask your own question.