+ Start a Discussion
Adam RycroftAdam Rycroft 

Test Class Compile Error: Variable Does Not Exist

Hi,

I'm modifying an existing trigger that was created to work in a similar fashion on a different object. The Apex Class and Trigger work fine, but in the Test Class, I get  Compile Error: Variable does not exist: Information_Date__c at line 49 column 25. Can anyone help to figure out what's going on? The line in question is: Information_Date__c = date.newInstance(2017, 1, 1),

@isTest
public class testProcessHealthInsurance {
    
    public static void createClientAndHealthInsurance(integer numOfClients, integer numOfHealthInsurance){
        
        list<account> aList = new list<account>();
        
        for(integer i = 1; i <= numOfClients; i++){
            account newA = new account(
                firstname = 'Test',
                lastname = 'Client',
                social_security_number__c = '000-00-0000',
                personBirthdate = date.newInstance(1980, 1, 1),
                gender__c = 'Female',
                ethnicity__c = 'Client refused',
                language__c = 'English',
                hiv_status__c = 'AIDS',
                secondary_disability__c = 'No Secondary Disability'
            );
            aList.add(newA);
        }
    
      insert aList;
        
        list<Health_Insurance_Coverage__c> HealthInsuranceList = new list<Health_Insurance_Coverage__c>();
        
        for(account a : aList){
            for(integer i = 1; i <= numOfHealthInsurance; i++){
                
                if(i<=12){
                    Health_Insurance_Coverage__c d = new Health_Insurance_Coverage__c(
                        Information_Date__c = date.newInstance(2017, i, 1),
                        Covered_by_Health_Insurance__c = 'No',
                        ADAP__c = 'No',
                        Medi_Cal__c = 'No',
                        Medicare__c = 'No',
                        State_Children_s_Health_Insurance__c = 'No',
                        State_Health_Insurance_for_Adults__c = 'No',
                        Veteran_s_Administration_Medical_Service__c = 'No',
                        Employer_Provided_Health_Insurance__c = 'No',
                        Private_Pay_Health_Insurance__c = 'No',
                        Ryan_White__c = 'No',
                        client__c = a.id
                    );                    
                  HealthInsuranceList.add(d);
                    
                } else {
                    Health_Insurance_Coverage__c d = Health_Insurance_Coverage__c(
                        Information_Date__c = date.newInstance(2017, 1, 1),
                        Covered_by_Health_Insurance__c = 'No',
                        ADAP__c = 'No',
                        Medi_Cal__c = 'No',
                        Medicare__c = 'No',
                        State_Children_s_Health_Insurance__c = 'No',
                        State_Health_Insurance_for_Adults__c = 'No',
                        Veteran_s_Administration_Medical_Service__c = 'No',
                        Employer_Provided_Health_Insurance__c = 'No',
                        Private_Pay_Health_Insurance__c = 'No',
                        Ryan_White__c = 'No',
                        client__c = a.id
                    );                
                    HealthInsuranceList.add(d);
                }
            }
        }
        
        insert HealthInsuranceList;
        
        list<Health_Insurance_Coverage__c> dCheck = [select id, client__c, status__c, information_date__c from Health_Insurance_Coverage__c];
        system.debug(dCheck);
        
  }
    
    public static testMethod void insertNewHealthInsurance(){
        
        createClientAndHealthInsurance(1,2);
        
        account a = [select id from account limit 1];
        
        Health_Insurance_Coverage__c d = new Health_Insurance_Coverage__c(
          information_date__c = date.newInstance(2017, 02, 15),
          Covered_by_Health_Insurance__c = 'No',
          ADAP__c = 'No',
          Medi_Cal__c = 'No',
          Medicare__c = 'No',
          State_Children_s_Health_Insurance__c = 'No',
          State_Health_Insurance_for_Adults__c = 'No',
          Veteran_s_Administration_Medical_Service__c = 'No',
          Employer_Provided_Health_Insurance__c = 'No',
          Private_Pay_Health_Insurance__c = 'No',
          Ryan_White__c = 'No',
          client__c = a.id
        );
        
        test.startTest();
        
        insert d;
        
        test.stopTest();
        
        Health_Insurance_Coverage__c dUpdated = [select id, status__c from Health_Insurance_Coverage__c where information_date__c = 2017-02-15];
        
        system.assertEquals('Current',dUpdated.status__c);
        
    }
    
    public static testMethod void insertMultipleHealthInsurance(){
        
        test.startTest();
        
        createClientAndHealthInsurance(1,2);
        
        test.stopTest();
        
        account a = [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account limit 1];
        
        for(Health_Insurance_Coverage__c d : a.Health_Insurance_and_Medical_Coverage__r){
            
            if(d.id == a.Health_Insurance_and_Medical_Coverage__r[0].id){
                system.assertEquals('Current',d.status__c);
            } else {
                system.assertEquals('Past',d.status__c);
            }
            
        }
        
    }
    
    public static testMethod void deleteHealthInsurance(){
        
        createClientAndHealthInsurance(1,2);
        
        account a = [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account limit 1];
        
        list<Health_Insurance_Coverage__c> dListToDelete = new list<Health_Insurance_Coverage__c>();
        
        Health_Insurance_Coverage__c dToDelete = [select id from Health_Insurance_Coverage__c where status__c = 'current' limit 1];
        
        test.startTest();
        
        delete dToDelete;
        
        for(account aUpdated : [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account where id = :a.id]){
            system.assertEquals(1,aUpdated.Health_Insurance_and_Medical_Coverage__r.size());
            for(Health_Insurance_Coverage__c d : aUpdated.Health_Insurance_and_Medical_Coverage__r){
                system.assertEquals('Current',d.status__c);
            }
        }
        
        Health_Insurance_Coverage__c dToUndelete = [select id from Health_Insurance_Coverage__c where isdeleted = true limit 1 ALL ROWS];
        
        undelete dToUndelete;
        
        for(account aUpdated : [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account where id = :a.id]){
            system.assertEquals(2,aUpdated.Health_Insurance_and_Medical_Coverage__r.size());
            for(Health_Insurance_Coverage__c d : aUpdated.Health_Insurance_and_Medical_Coverage__r){
                if(d.id == aUpdated.Health_Insurance_and_Medical_Coverage__r[0].id){
                  system.assertEquals('Current',d.status__c);
                } else {
                    system.assertEquals('Past',d.status__c);
                }
            }
        }
        
        test.stopTest();
        
    }
    
    public static testMethod void updateHealthInsuranceDate(){
        
        createClientAndHealthInsurance(1,2);
        
        account a = [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account limit 1];
        
        list<Health_Insurance_Coverage__c> dList = new list<Health_Insurance_Coverage__c>();
        
        for(Health_Insurance_Coverage__c d : a.Health_Insurance_and_Medical_Coverage__r){
            if(d.id == a.Health_Insurance_and_Medical_Coverage__r[0].id){
                d.information_date__c = date.newInstance(2016,12,1);
                dList.add(d);
            }
        }
        
        test.startTest();
        
        checkRecursive.reset();
        update dList;
        
        test.stopTest();
        
        account aUpdated = [select id, (select id, status__c, information_date__c from Health_Insurance_and_Medical_Coverage__r order by information_date__c desc, createddate desc) from account limit 1];
        
        list<Health_Insurance_Coverage__c> dListUpdated = new list<Health_Insurance_Coverage__c>();
        
        for(Health_Insurance_Coverage__c d : aUpdated.Health_Insurance_and_Medical_Coverage__r){
            
            if(d.id == aUpdated.Health_Insurance_and_Medical_Coverage__r[0].id){
                system.assertEquals('Current',d.Status__c);
                system.assertEquals(date.newInstance(2017,1,1),d.information_date__c);
            } else {
                system.assertEquals('Past',d.Status__c);
            }
        }
        
    }
    
    public static testMethod void testBulkHealthInsurance(){
        
        createClientAndHealthInsurance(200,10);
        
        list<Health_Insurance_Coverage__c> dListToModify = new list<Health_Insurance_Coverage__c>();
        
        for(Health_Insurance_Coverage__c d : [select id, information_date__c, status__c from Health_Insurance_Coverage__c where status__c = 'current']){
            system.assertEquals(date.newInstance(2017,10,1),d.information_date__c);
            Health_Insurance_Coverage__c dToUpdate = new Health_Insurance_Coverage__c(
                id = d.id,
              information_date__c = date.newInstance(2017,8,15)
            );
            dListToModify.add(dToUpdate);
        }
        
        checkRecursive.reset();
        update dListToModify;
        
        list<Health_Insurance_Coverage__c> dListToDelete = new list<Health_Insurance_Coverage__c>();
        
        for(Health_Insurance_Coverage__c d : [select id, information_date__c, status__c from Health_Insurance_Coverage__c where status__c = 'current']){
            system.assertEquals(date.newInstance(2017,9,1),d.information_date__c);
            dListToDelete.add(d);
        }
        
        delete dListToDelete;
        
        for(Health_Insurance_Coverage__c d : [select id, information_date__c, status__c from Health_Insurance_Coverage__c where status__c = 'current']){
            system.assertEquals(date.newInstance(2017,8,15),d.information_date__c);
        }
        
    }

}
Nayana KNayana K
Health_Insurance_Coverage__c d = new Health_Insurance_Coverage__c(
                        Information_Date__c = date.newInstance(2017, 1, 1),
                        Covered_by_Health_Insurance__c = 'No',
                        ADAP__c = 'No',
                        Medi_Cal__c = 'No',
                        Medicare__c = 'No',
                        State_Children_s_Health_Insurance__c = 'No',
                        State_Health_Insurance_for_Adults__c = 'No',
                        Veteran_s_Administration_Medical_Service__c = 'No',
                        Employer_Provided_Health_Insurance__c = 'No',
                        Private_Pay_Health_Insurance__c = 'No',
                        Ryan_White__c = 'No',
                        client__c = a.id
                    );

You are just missing "new" keyword!