+ Start a Discussion
jhansisridhar_2011jhansisridhar_2011 

URGENT : Regarding If Condition in test class for trigger.

Hi All,

 

It's Very urgent !!

Can anyone help to write a test class for below code.

 

Need to satisfy if condition.I created 2 records of an object with Akreos_MIL__c = 220 and Akreos_MIL__c = 210. but, it;s not working to increase code coverage.

 

if (trigger.OldMap.get(pv.Id).Akreos_MIL__c != pv.Akreos_MIL__c) {

.....

...

....

 

}

 

Thanks in Advance.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You need to test only one record, such as:

 

record a = new SObject(...);
a.Akreos_MIL__c = 220;
insert a;
a.Akreos_MIL__c = 210;
update a;

This will test your conditional branch, assuming the trigger uses "before update" or "after update" events.