You need to sign in to do that
Don't have an account?

Need help in test class for trigger
Hi All,
I need help in writing test class for trigger. I have written but its giving only 65%. Please help me.
Thanks in Advance
I need help in writing test class for trigger. I have written but its giving only 65%. Please help me.
trigger test1 on obj1__c (after insert, after update) { if(trigger.isAfter&& (trigger.isinsert || trigger.isUpdate)) { test3.method1(Trigger.New); } }
public class test3 { public static void method1(List<Obj1__c> o1) { map<string, obj1__c> ObjMap = new map<string, obj1__c>(); for(obj1__c obj: o1) { if (obj.Shared_Field__c != Null) { ObjMap.put(obj.Shared_Field__c, obj); } } List<obj2__c> obj2l = [SELECT Id, Shared_Field__c, F1__c,f2__c FROM obj2__c WHERE Shared_Field__c IN :ObjMap.KeySet()]; List<obj2__c> obj2list = new List<obj2__c>(); for(obj2__c c: obj2l) { obj1__c obj = ObjMap.get(c.Shared_Field__c); c.f1__c = obj.f1__c; c.f2__c = obj.f2__c; obj2list.add(c); } if(obj2list.size() > 0) { update obj2list; } } }
Thanks in Advance
Try this below test class:
Plese like and mark it as best answer if it resolve your query.
Thanks,
Jolly Birdi
All Answers
It is difficult to say anything without the actual test class. Could you add that?
FYI, On developer console, after running the test class, if you go to the 'test3' class and click the 'code coverage' dropdown on the top left. It will highlight (red color) the code which was not covered by the test class.
This is my test class.
Try this below test class:
Plese like and mark it as best answer if it resolve your query.
Thanks,
Jolly Birdi