[SalesForce] Importing RecordType as test data with Test.loadData()

I am trying to import some test data before tests with a csv file and the Test.load() method.
I am not being able to figure out how to declare the load method for the RecordTypes I have in a file.
Here is what I have:

static testMethod void init() {
    List<sObject> recordTypes = Test.loadData(?????, 'esb_record_type_test_data');
    List<sObject> accounts = Test.loadData(Account.sObjectType, 'esb_account_test_data');
    List<sObject> contacts = Test.loadData(Contact.sObjectType, 'esb_contact_test_data');
    List<sObject> customers = Test.loadData(Customer__c.sObjectType, 'esb_customer_test_data');
}

What should I declare in?

Best Answer

  1. Record types are not separate object. Adding extra column in your CSV file with RecordTypeID should work. So while inserting from Test.Load(), record will be created based on record types.

  2. Alternately if there is change in recordtypeid use below syntax to get RecordtypeId and logic.

Example code:

Id RecordTypeIdValue = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Development').getRecordTypeId();

for(Account accountrecord : accounts) {
    accountrecord.Recordtypeid=RecordTypeIdValue;
}

Hope this helps.

Thanks Pradeep

Related Topic