Showing posts with label convert lead using Apex. Show all posts
Showing posts with label convert lead using Apex. Show all posts

Monday, January 27, 2014

How to convert lead using Apex

How to convert lead using Apex

Lead myLead = new Lead(LastName = 'Foo', Company='Foo Bar');
insert myLead;

Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());