Skip to main content
1 of 2

Test Trigger Auto Convert Lead To Contact

I have the following Trigger but how do I write a Test for this so I can put it into production?

trigger web2LeadConvert on Lead (after insert) {
Database.LeadConvert[] converts = new Database.LeadConvert[0];
for(Lead record: Trigger.new) {
    if(record.Web_To_Lead__c == 'Yes') {
        Database.LeadConvert thisLead = new Database.LeadConvert();
        thisLead.setLeadId(record.Id);
        thisLead.setConvertedStatus('Qualified');
        converts.add(thisLead);
    }
}
Database.convertLead(converts);
}

Thanks!