Basic Test Class for Trigger

By | January 21, 2020

Hi,this program shows test class for trigger

Trigger

trigger TestTrigger on Lead (before insert) {
    for(Lead l:trigger.new){
        if(l.Leadsource=='Web'){
            l.Rating='Warm';
        }
    }
}

Test Class

@isTest
private class TestTriggerLead {
    static testMethod void testme(){
        Lead l=new Lead();
        l.LastName='Testing';
        l.FirstName='Salesforcecodes';
        l.Company='Wipro';
        l.LeadSource='Web';
        insert l;
        Lead leads=[select rating from Lead where id=:l.Id];
        system.assertEquals('Warm', leads.Rating);
    }
}

Share this...
Share on Facebook
Facebook
Email this to someone
email

Leave a Reply

Your email address will not be published. Required fields are marked *