You need to sign in to do that
Don't have an account?
Chanagan Sakulteera
How to write test class trigger and apex class?
Hi all, I have some experience with apex class but I don't understand how to coding with test class.
If you have any assisting or link that I would better, I really appreciate it.
Last of all, I put some of my trigger in the below to be example to get clearer picture about test class coding.
If you have any assisting or link that I would better, I really appreciate it.
Last of all, I put some of my trigger in the below to be example to get clearer picture about test class coding.
trigger trgLead on Lead (before insert,before update) { Map<String, Lead> leadMap = new Map<String, Lead>(); for(Lead lead : System.Trigger.new){ // Make sure we don't treat an email address that // isn't changing during an update as a duplicate. if((lead.Email != null)&&(System.Trigger.isInsert || (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))){ //Make sure another new lead isn't also a duplicate if(leadMap.containsKey(lead.Email)){ lead.Email.addError('Another new lead has the ' + ' same email address.'); }else{ leadMap.put(lead.Email, lead); } } } // Using a single database query, find all the leads in // the database that have the same email address as any // of the leads being inserted or updated. for(Lead lead : [Select Email from Lead where Email in : leadMap.KeySet()]){ Lead newLead = leadMap.get(lead.Email); newLead.Email.addError('A lead with this email ' + ' address already exist.'); } }This trigger have check dupdicate in lead.
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
my point of view u have to create a data factory based on all test scenario then apply insert and update that will help to full covered as well as well tested code ...