How to convert lead using Apex?

Sample code:

Lead myLead = new Lead(LastName = ‘Foo’, Company=’Foo Bar’);
insert myLead;    
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);
lc.ConvertedStatus = ‘Closed – Converted’;
Database.LeadConvertResult lcr = Database.convertLead(lc);                
System.assert(lcr.isSuccess());

Cheers!!!

Leave a Reply