function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Varun AnnadataVarun Annadata 

Test Class giving System.List Exception while deploying to Production

@isTest

private class ContactInfoDeleteTriggerTestMVN {
    
    @isTest 
    private static void testDelete() {
        TestDataFactoryMVN.createFieldSetMappings();
        TestDataFactoryMVN.createPSSettings();

        Account doc = TestDataFactoryMVN.createPhysician();
        Account pat = TestDataFactoryMVN.createMember();
        Program_MVN__c prog = TestDataFactoryMVN.createProgram();
        Program_Stage_MVN__c parent = TestDataFactoryMVN.createParentProgramStage(prog);
        Program_Stage_MVN__c child = TestDataFactoryMVN.createChildProgramStage(prog, parent);
        Program_Member_MVN__c member = TestDataFactoryMVN.createProgramMember(prog, pat);
        Address_vod__c add = TestDataFactoryMVN.createTestAddress(pat);

        List<Contact_Information_MVN__c> info = [SELECT Id,Name FROM Contact_Information_MVN__c WHERE Address_MVN__c = :add.Id];
        system.debug('Varun1'+info);
        //System.assertEquals(1, info.size(), 'Incorrect number of contact information records retrieved.');

        List<Communication_Preference_MVN__c> pref = [SELECT Id,Name FROM Communication_Preference_MVN__c WHERE Contact_Information_MVN__c = :info[0].Id];
        system.debug('VArun'+pref);
        System.assertEquals(1, pref.size(), 'Incorrect number of communication preference records retrieved.');
        Id testCommPrefId = pref[0].Id;

        delete info[0];

        info = [SELECT Id FROM Contact_Information_MVN__c WHERE Address_MVN__c = :add.Id];
        pref = [SELECT Id FROM Communication_Preference_MVN__c WHERE Id = :testCommPrefId];
        List<Address_vod__c> adds = [SELECT Id FROM Address_vod__c WHERE Id = :add.Id];

        System.assertEquals(0, info.size(), 'Should have returned no contact information records');
        System.assertEquals(0, pref.size(), 'Should have returned no communcation preference records');
        System.assertEquals(0, adds.size(), 'Should have returned no address records');
    }
}

I am getting System.List Exception at Line         List<Communication_Preference_MVN__c> pref = [SELECT Id,Name FROM Communication_Preference_MVN__c WHERE Contact_Information_MVN__c = :info[0].Id];

Any help why this error is coming in production?
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Varun, 
I think you are getting error as info[0].Id getting the List exception as info[0] has no element. Thereby, my coclusion is add.Id is has a null value. In that case please check TestDataFactoryMVN.createTestAddress(pat); and TestDataFactoryMVN.createMember(); is working properly or not in the production org. If it is working in Sandbox and you are only getting error in Production them some of Admin level data link Custom Settings or Custom metadata Types or some other data related configurations are wrongly set up in your production org. Please verifiy accordingly and let us know.

Thanks
Prosenjit