0

I am working on a Data Factory test class and I was able to successfully load relational data for Account, Case, WorkOrder, User, InsurancePolicy and couple of other custom objects by providing Id in the csv file. But the assertion is failing on Producer object. Does anyone know if the Producer object has any limitations that is not documented anywhere?

Here's my code:

@isTest
public class DataFactoryTestUtility {

    public static void batchDataSetup(){
        //Load CSV file saved in static resource  
        
        //List<SObject> accountList = Test.loadData(Account.sObjectType,'TestAccountCreation');
        //List<SObject> insurancePolicyList = Test.loadData(InsurancePolicy.sObjectType,'TestInsurancePolicyCreation'); ;
        //List<SObject> insurancePolicyParticipantList = Test.loadData(InsurancePolicyParticipant.sObjectType,'TestInsurancePolicyParticipantCreation');
        //List<SObject> userList = Test.loadData(User.sObjectType,'TestUserCreation');
        //List<SObject> workorderList = Test.loadData(WorkOrder.sObjectType,'TestWorkorderCreation');
        List<SObject> producerList = Test.loadData(Producer.sObjectType,'TestProducerCreation');
    }
    
    @isTest
    static void testLoadProducersFromStaticResource() {
        List<Producer> prods = [SELECT ID FROM Producer];
        System.assertEquals(prods.size(), 100);
    }
}

All commented lines in the code are working as expected the uncommented producerList. Data in csv file (saved as .csv):

Id,Name,ProducerSourceSystemId__c
producerid001,L23A1,L23A1
producerid002,L23A2,L23A2
producerid003,L23A3,L23A3
producerid004,L23A4,L23A4
producerid005,L23A5,L23A5
producerid006,L23A6,L23A6
producerid007,L23A7,L23A7
producerid008,L23A8,L23A8
producerid009,L23A9,L23A9
producerid010,L23A10,L23A1

Note: This worked from Anonymous window:

Producer p = new Producer(
    Name='L23A100',
    ProducerSourceSystemId__c='L23A100' 
);
insert p;
4
  • Your question just lists 10 entries in the csv, but the assert is for 100, is that just because you didn't paste the full csv?
    – rael_kid
    Aug 23 at 14:09
  • @rael_kid - That is correct. I added 10 rows of csv file to show the format but it actually has 100 records.
    – SunnyG
    Aug 23 at 14:11
  • In the test method itself, I don't see batchDataSetup() being called, and it's not annotated with @testSetup, could that be the problem?
    – rael_kid
    Aug 23 at 14:12
  • @rael_kid I was actually calling batchDataSetup method in a different test class which is why i didn't set it as testSetup but your question made me check the line where I should calling DataFactoryTestUtility.batchDataSetup() and it turns out I am calling the same method from different test utility class which will be decommissioned sooner. Silly mistake from me :|
    – SunnyG
    Aug 23 at 14:37

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.