LeadConvert

The convertLead Database method converts a lead into an account and contact, as well as (optionally) an opportunity. TheconvertLead takes an instance of the Database.LeadConvert class as a parameter. 

Example

This example shows how to use the Database.convertLead method to convert a lead. It inserts a new lead, creates aLeadConvert object, sets its status to converted, then passes it to the Database.convertLead method. Finally, it verifies that the conversion was successful.

Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons');
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.debug('LeadConvertedResult=='+lcr);



0 comments:

Post a Comment