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:

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');
    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):


Note: This worked from Anonymous window:

Producer p = new Producer(
insert p;
  • 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.