//Lead Conversion
// creating a sample lead for conversion
Lead ld1 = new Lead();
ld1.lastName = 'test'; // these 2 are the required fields in my Org, as per your Org required fields
ld1.Company = 'test'; // assign values to each of the required fields
insert ld1;
// converting the created lead
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(ld1.id);
//lc.setAccountId(acc2.Id); // you can set the Account Id to which you want the lead to be converted, if not specified, it creates a new account.
//lc.setContactId(con3.id); // you can set the Contact Id to which you want the lead to be converted, if not specified, it creates a new Contact.
//lc.setDoNotCreateOpportunity(true); // this will not create a new opportunity on lead conversion
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());
system.debug('-----------'+lcr.getContactId()); // will return you the converted Contact Id
system.debug('-----------'+lcr.getAccountId()); // will return you the converted Account Id
Hi,
Try these steps:
Go to the Lead Detail Page for a particular Record then Press the Convert button overt there and it will create the account as well as opportunity.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
if you want to do it through Apex,
below example should help you.
Let me know if this helps :)