You need to sign in to do that
Don't have an account?
Neeraj Sharma 103
Hi Everyone how to write test class for below trigger with Trigger handler
Trigger trigger LeadTrigger on Lead(before insert, before Update) { if (trigger.isInsert && trigger.isBefore) { LeadTriggerHandler.onBeforeInsert(trigger.new); } else if (trigger.isUpdate && trigger.isBefore) { LeadTriggerHandler.onBeforeUpdate(trigger.new, trigger.oldMap); } }
TrigerHandlerClass public class LeadTriggerHandler { public static String STATUS_SELF_REPRESENTED = 'Self Represented'; public static void onBeforeInsert(list <Lead> newLeadList){ updateFldsOnLead(newLeadList, null); } public static void onBeforeUpdate(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){ updateFldsOnLead(newLeadList, oldLeadMap); } public static void updateFldsOnLead(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){ map<String, list<lead>> zipCodeLeadMap = new Map <String, list<lead>> (); for(Lead ld: newLeadList){ if(ld.Status != STATUS_SELF_REPRESENTED && ld.PostalCode != null){ if(!zipCodeLeadMap.containsKey(ld.PostalCode)){ zipCodeLeadMap.put(ld.PostalCode, new list<lead>()); } zipCodeLeadMap.get(ld.PostalCode).add(ld); } } if(zipCodeLeadMap.size() > 0){ for(Lead_WF_Configuration__mdt ldConfigCMD: [Select Id, Zip_Postal__c, State__c, County__c,OwnerID__c From Lead_WF_Configuration__mdt]){ for(String zip: zipCodeLeadMap.keySet()){ if(String.valueOf(ldConfigCMD.Zip_Postal__c).contains(zip)){ for(Lead ld: zipCodeLeadMap.get(zip)){ ld.State = ldConfigCMD.State__c; ld.County__c = ldConfigCMD.County__c; ld.OwnerId = ldConfigCMD.OwnerID__c; } } } } } } }
Use the following test class. Please update the data and add assert as per your requirement:
Let me know if it solves your problem.
Many Thanks,
Sunil Rathore
All Answers
Use the following test class. Please update the data and add assert as per your requirement:
Let me know if it solves your problem.
Many Thanks,
Sunil Rathore
Your Code Coverage is 47% How to cover below part
In testLeadUpdate method ;
add values for Status and Postal Code in the lead record i.e in objLead and objSecondLead.
Also, take care that Status value should satisfy this condition ld.Status != STATUS_SELF_REPRESENTED.
Let me know if this works for you.
Many Thanks,
Sunil Rathore
Can you tell me how to write and which condtion i write in system.assert() method
thanks
Neeraj Sharma
Use the following lines in both methods: Let me know if it runs successfully.
Many Thanks,
Sunil Rathore
Thanku So Much Now its Working
Thanks
Neeraj Sharma