+ Start a Discussion
KyoKyo 

Problem For Loop in Test Class not Work!

I'm Test Class and Trigger not work. becasue for loop 

 

trigger MarkforDelAllinCon on Contact(before Update) {
set<ID> setContactID = new set<ID>();
    
        for(Contact Con: Trigger.new){
        if(Con.MarkforDelete__c == true){   
            setContactID.Add(Con.id);  
        }
        }
             
        List<Relationship__c > lstRel = [Select id,Mark_for_Delete__c,Contact_ID__c,Account_ID__c,Rev_Account_ID__c,Rev_Contact_ID__c  from Relationship__c Where  Contact_ID__c in :   setContactID and Mark_for_Delete__c !=: True];
           
        for(Contact Con: Trigger.new){
            if(lstRel.size() != 0 ){
                     for(Relationship__c Res : lstRel){ 
                        Res.Contact_ID__c  = Con.id;
                        Res.Rev_Contact_ID__c  = Con.id;            
                        Res.Mark_for_Delete__c = true;
                        update Res;
                     }                  
            }
}
}

 Error in Test Class Line :

for(Relationship__c Res : lstRel){

                      Res.Contact_ID__c  = Con.id;

                      Res.Rev_Contact_ID__c  = Con.id;

                      Res.Mark_for_Delete__c = true; 

                      update Res; 

         }    

 

@isTest
private class TestMarkforDelAllinCon {
    static testMethod void myTest() {
    
    Account objAcc = new Account();
    objAcc.Name = 'testAcc1';
    objAcc.AccountNumber = 'TestA00001';
    insert objAcc;
    
    Account objAccRev = new Account();
    objAccRev.Name = 'testAcc2';
    objAccRev.AccountNumber = 'TestA00001';
    insert objAccRev;
    
    Contact con = new Contact();
    con.AccountID = objAcc.id;
    con.LastName = 'TestCon1';
    con.MarkforDelete__c = True;
    insert con;
    update con;
    
    Contact ConRev = new Contact();
    ConRev.AccountID = objAcc.id;
    ConRev.LastName = 'TestCon2';
    ConRev.MarkforDelete__c = True;
    insert conRev;
    update conRev;
    
    List<Relationship__c>  Rel = new List<Relationship__c> ();
    ApexPages.currentPage().getParameters().put('id',con.id);
        for(Relationship__c Res : Rel){
        Res.Contact_ID__c = Con.id;
        Res.Rev_Contact_ID__c = Con.id;
        Res.Mark_for_Delete__c = true;
        update Res;
        }    
}
}

 Thank you so much.

kiranmutturukiranmutturu

rel defined in the loop before line and iterating with that with out filling any values...