+ Start a Discussion
Nazira ANazira A 

trigger.isUpdate && isBefore in test class not covered

Hi ,
In my test class trigger.isUpdate && isBefore is not coverd.Could any one help ?

Thanks ,
trigger IssuerUpdate on Issuer__c (before update)
{
    //uisng handler class to avoid recrisive
    if(trigger_handler.runisuuer())
    {    
        for(Issuer__c newIssuer : trigger.new)
        {
            //checking the status 
            if( newIssuer.Status__c == 'Approved')
            {
                if(trigger.isUpdate && trigger.isBefore)
                {
                    Issuer__c oldIssuer = trigger.oldMap.get(newIssuer.Id);
                    newIssuer.Ass1__c=  oldIssuer.Ass0__c;
                    newIssuer.DbtQ1__c= oldIssuer.DbtQ0__c;
                    newIssuer.DtE1__c = oldIssuer.DtE0__c;
                    newIssuer.Earn1__c= oldIssuer.Earn0__c;
                    newIssuer.Eqt1__c = oldIssuer.Eqt0__c;
                    newIssuer.MFRS1__c= oldIssuer.MFRS0__c; 
                    newIssuer.RA1__c  = oldIssuer.RA0__c; 
                    newIssuer.RevQ1__c= oldIssuer.RevQ0__c;
                    newIssuer.Rev1__c = oldIssuer.Rev0__c;
                    newIssuer.RE1__c  = oldIssuer.RE0__c; 
                    //'0' values null after update the Status Approved
                    newIssuer.RevQ0__c = null;
                    newIssuer.Rev0__c=null;
                    newIssuer.Ass0__c=null;
                    newIssuer.DbtQ0__c=null;
                    newIssuer.DtE0__c=null;
                    newIssuer.Earn0__c=null; 
                    newIssuer.Eqt0__c=null;
                    newIssuer.MFRS0__c=null;
                    newIssuer.RA0__c=null;
                    newIssuer.RE0__c=null;
                    
                    //RevQ---
                    newIssuer.RevQ2__c= oldIssuer.RevQ1__c;
                    newIssuer.RevQ3__c= oldIssuer.RevQ2__c;
                    newIssuer.RevQ4__c= oldIssuer.RevQ3__c;
                    
                    //Rev
                    newIssuer.Rev2__c= oldIssuer.Rev1__c;
                    newIssuer.Rev3__c= oldIssuer.Rev2__c;
                    newIssuer.Rev4__c= oldIssuer.Rev3__c;
                    //ass
                    newIssuer.Ass2__c= oldIssuer.Ass1__c;
                    newIssuer.Ass3__c= oldIssuer.Ass2__c;
                    newIssuer.Ass4__c= oldIssuer.Ass3__c;
                    //DbtQ0
                    newIssuer.DbtQ2__c= oldIssuer.DbtQ1__c;
                    newIssuer.DbtQ3__c= oldIssuer.DbtQ2__c;
                    newIssuer.DbtQ4__c= oldIssuer.DbtQ3__c;
                    //DtE1__c
                    newIssuer.DtE2__c= oldIssuer.DtE1__c;
                    newIssuer.DtE3__c= oldIssuer.DtE2__c;
                    newIssuer.DtE4__c= oldIssuer.DtE3__c;
                    //Earn0__c
                    newIssuer.Earn2__c= oldIssuer.Earn1__c;
                    newIssuer.Earn3__c= oldIssuer.Earn2__c;
                    newIssuer.Earn4__c= oldIssuer.Earn3__c;
                    //Earn0__c
                    newIssuer.Eqt2__c= oldIssuer.Eqt1__c;
                    newIssuer.Eqt3__c= oldIssuer.Eqt2__c;
                    newIssuer.Eqt4__c= oldIssuer.Eqt3__c;
                    //MFRS
                    newIssuer.MFRS2__c= oldIssuer.MFRS1__c;
                    newIssuer.MFRS3__c= oldIssuer.MFRS2__c;
                    newIssuer.MFRS4__c= oldIssuer.MFRS3__c;
                    //R01__c
                    newIssuer.RA2__c= oldIssuer.RA1__c;
                    newIssuer.RA3__c= oldIssuer.RA2__c;
                    newIssuer.RA4__c= oldIssuer.RA3__c;
                    //RE0__c
                    newIssuer.RE2__c= oldIssuer.RE1__c;
                    newIssuer.RE3__c= oldIssuer.RE2__c;
                    newIssuer.RE4__c= oldIssuer.RE3__c;
                }
            }
        }
    }
}

 
Sitarama MurthySitarama Murthy
Hi Nazlra,

Try to re-order the if conditioins:
 
If(Trigger.isUpdate && Trigger.isBefore)
{
      if(trigger_handler.runisuuer()){
           for(Issuer__c newIssuer : trigger.new){
                if( newIssuer.Status__c == 'Approved'){
                     //your code block
                }
               
           }
      }
}
Thanks,
Ram
 
Nazira ANazira A
Hi Ram ,
Still its not covering ,here is my test class
@isTest(SeeAllData=true)
Public class IssuerUpdate_test
{
    @isTest static void checkUpdateIssuer()
    {
        test.startTest();
        Issuer__c issuer_Obj = new Issuer__c();
        
        issuer_Obj.Status__c = 'Ready For Review';
        issuer_Obj.MFA_Recommendation__c='hold';
        issuer_Obj.RevQ0__c=123;
        issuer_Obj.Ass0__c=147;
        issuer_Obj.Rev0__c=478;
        issuer_Obj.DbtQ0__c=582;
        issuer_Obj.DtE0__c=255;
        issuer_Obj.Earn0__c=258;
        issuer_Obj.Eqt0__c=963;
        issuer_Obj.MFRS0__c=869;
        issuer_Obj.RA0__c=285;
        issuer_Obj.RE0__c=395;
        Insert issuer_Obj;
     
     	issuer_Obj.Status__c = 'Approved';
        issuer_Obj.RevQ1__c = issuer_Obj.RevQ0__c;
        issuer_Obj.RevQ2__c = issuer_Obj.RevQ1__c;
        issuer_Obj.RevQ3__c = issuer_Obj.RevQ2__c;
        issuer_Obj.RevQ4__c = issuer_Obj.RevQ3__c;
        update issuer_Obj;
        test.stopTest();
   }
}
Sitarama MurthySitarama Murthy
Hi Nazlra,

Try Below code:
 
@isTest
Public class IssuerUpdate_test
{
    @isTest static void checkUpdateIssuer()
    {
        
        Issuer__c issuer_Obj = new Issuer__c();
        
        issuer_Obj.Status__c = 'Ready For Review';
        issuer_Obj.MFA_Recommendation__c='hold';
        issuer_Obj.RevQ0__c=123;
        issuer_Obj.Ass0__c=147;
        issuer_Obj.Rev0__c=478;
        issuer_Obj.DbtQ0__c=582;
        issuer_Obj.DtE0__c=255;
        issuer_Obj.Earn0__c=258;
        issuer_Obj.Eqt0__c=963;
        issuer_Obj.MFRS0__c=869;
        issuer_Obj.RA0__c=285;
        issuer_Obj.RE0__c=395;
        Insert issuer_Obj;


        Issuer__c issuer_Obj1 = new Issuer__c();
        issuer_Obj1.Id = issuer_Obj.Id;
     	issuer_Obj1.Status__c = 'Approved';
        issuer_Obj1.RevQ1__c = issuer_Obj.RevQ0__c;
        issuer_Obj1.RevQ2__c = issuer_Obj.RevQ1__c;
        issuer_Obj1.RevQ3__c = issuer_Obj.RevQ2__c;
        issuer_Obj1.RevQ4__c = issuer_Obj.RevQ3__c;


        test.startTest();
        update issuer_Obj;
        test.stopTest();
   }
}