+ Start a Discussion
skdevskdev 

Test class for after update trigger

I have a trigger on after insert and after update

within the code i have a class that limits the trigger from firing once as i have a workflow field update

In my test class i have inserted a new record and then later i am updating it. its not covering the update part of it.

Can anyone tell me what i am missing in the code.

kiranmutturukiranmutturu

on the fly its difficult to say

ChizChiz

Yep. Code, pelase!

You may have some 'if statement' which is false.

skdevskdev

@istest
Private class CalStatusTest_cls{    
  static testMethod void testMeth(){
      dmlog__c a = new dmlog__c();
      a.Phase__c = 'Draft';
      insert a;
    
      a.Phase__c = 'Progress'; 
      update a;

  }
}


ChizChiz

And trigger. pelase.

skdevskdev

trigger TempTrigger on dmlog__c (After Insert, After Update) {

if(!Validator_cls.hasAlreadyDone() ){ //Util class used to limit the trigger to fire once
If(Trigger.isUpdate){
for(dmlog__c d:Trigger.new){
if(phase changes)
add to ASet
}
-----
}

List<Temp__c> TempAEList = New List<Temp__c>([Select A__c, Phase__c
From Temp__c
Where A__c in :ASet
]);

if(TempAEList.size() > 0){
-----

}
else{
-----
}
if(!TempAInsert.isEmpty())
Insert TempAInsert;
if(!TempAUpdate.isEmpty())
update TempAUpdate;
}
if(Trigger.isInsert){
system.debug('Is Insert');
}
Validator_cls.setAlreadyDone();

}
}

ChizChiz

Put a system.debug(' --- nto validated --- '); after if(!Validator_cls.hasAlreadyDone() ){ and run test. In debug log you won't have "--- nto validated ---" I believe. So either hasAlreadyDone method perform badly or Validator_cls.setAlreadyDone(); performed during object insertion.