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

Test class not covering
-
trigger TaskCreatepromotionmember on Promotion_Member__c (before update) { Set<Id> createdByIds = new Set<Id>(); Set<Id> Managerid=new Set<Id>(); List<User> lstU2 = [select id,email,TL__c,ManagersId__c from User]; try { List<Promotion_Member__c> t2=[select id,Verification_Status__c,Verified__c from Promotion_Member__c WHERE Verification_Status__c='Complaint' LIMIT 1]; for(User u1:lstU2) { for(Promotion_Member__c pr:Trigger.New) { createdByIds.add(pr.createdById); Managerid.add(u1.ManagersId__c); } } Map<Id, User> userMap = new Map<Id,User>([select Name, Email,ManagersId__c from User where Id in :createdByIds]); for(Promotion_Member__c eq : Trigger.New) { Promotion_Member__c beforeUpdate = System.Trigger.oldMap.get(eq.Id); if(eq.Verification_Status__c=='Complaint' && eq.Verified__c==true && beforeUpdate.Verification_Status__c!= eq.Verification_Status__c) { // Promotion_Member__c eq=[select id,Complaint_Remarks__c,Complaints__c,Suggestion__c,Suggestion_Remarks__c,Call_Center_Remarks__c,createdbyId from Promotion_Member__c where id=:tsk.id]; //system.debug('Enquiry'+eq); Task Tk = new Task(); Tk.ownerid = userMap.get(eq.createdById).ManagersId__c; Tk.Call_Center_Comments__c=eq.Call_Center_Remarks__c; Tk.WhatId=eq.id; Tk.Suggestion__c=eq.Suggestion__c; Tk.Complaint__c=eq.Complaints__c; Tk.ActivityDate=system.today(); Tk.Priority='Normal'; Tk.Subject='PromotionMember Complaint'; insert Tk; Task Tk1 = new Task(); Tk1.ownerid =eq.createdbyId; Tk1.WhatId=eq.id; Tk1.Suggestion__c=eq.Suggestion__c; Tk1.Complaint__c=eq.Complaints__c; Tk1.ActivityDate=system.today(); Tk1.Call_Center_Comments__c=eq.Call_Center_Remarks__c; Tk1.Priority='Normal'; Tk1.Subject='PromotionMember Complaint'; insert Tk1; } } }Catch(Exception e) {} } @isTest(SeeAllData=True) Public Class TestTaskCreatepromotionmemberClass { Static TestMethod Void Emailpromotion() { Test.StartTest(); User lstU2 =[select id,email,TL__c,ManagersId__c from User where profile.Name='BD' LIMIT 1]; Tour_Program__c tr=new Tour_Program__c(); tr.From_Date__c=date.newinstance(2014, 3, 1); tr.To_Date__c=date.newinstance(2014, 3, 15); insert tr; List<Tour_Plan1__c > TourPlan=new List<Tour_Plan1__c >(); Tour_Plan1__c tp=new Tour_Plan1__c(); tp.Name='Tour Palan1234'; tp.Tour_Program__c=tr.id; insert tp; Site_Visit__c sv=new Site_Visit__c(); sv.Tour_Plan1__c=tp.id; sv.Architects_Meet_Actuals__c=1; sv.Boarers_Meet_Actuals__c=2; sv.Builders_Meet_Actuals__c=3; sv.Verification_Type__c='Complaint'; sv.Verified__c=true; insert sv; Promotion__c prm=new Promotion__c(); prm.Date__c=System.today(); prm.Type__c='Dealers Meet'; prm.Site_Visit__c=sv.id; insert prm; Promotion_Member__c pm=new Promotion_Member__c(); pm.Verified__c=true; pm.Promotions2__c=prm.id; pm.Verification_Status__c = 'Complaint'; pm.Call_Center_Remarks__c='Remarks'; pm.Call_Status__c='Completed'; insert pm; update pm; //Promotion_Member__c pm1= [SELECT id,Verification_Status__c FROM Promotion_Member__c WHERE id=:pm.id]; //update pm1; Task Tk1=new task(); Tk1.ActivityDate=system.today(); Tk1.Priority='Normal'; Tk1.Subject='Site Visit Complaint'; Tk1.whatId=pm.id; Tk1.Call_Center_Comments__c='Test'; Tk1.OwnerId=lstU2.ManagersId__c; insert Tk1; Task Tk2=new task(); Tk2.ActivityDate=system.today()+2; Tk2.Priority='Normal'; Tk2.Subject='Site Visit Complaint'; Tk2.whatId=pm.id; Tk2.OwnerId=userinfo.getuserid(); Tk2.Call_Center_Comments__c='Type'; insert Tk2; Test.StopTest(); } }
You actual trigger needs optimization. I see that you have for loop within for loop
Anyways. In your Test Class line 112 is supposed to cover the trigger, but in trigger there is a line that says below
It means you have to change the verification status from something else to complaint. then it goes into the loop.
Hope this helps
-
Remove @isTest(SeeAllData=True) and create the users your require in your test method
-
Add asserts to your test, currently your test doesn't actually test anything. It performs the opperation but then doesn't check the results.
In terms of your coverage, it looks like your trigger is checking if the Verification_Status__c field has changed on update. You don't change the value of this field between the your insert and your update.The following should allow you to cover the inside of your if statement.
I went through the code and find some bad practise eg using insert operation in for loop and exceution for loop which is not need in your code based on current stucture.