Many of the questions that I searched for on here deal with converting a Lead to either an existing account or contact.
My requirement is that I convert the lead to a new opportunity. This logic needs to be handled dynamically/automatically in Apex.
Most of the code snippets that I come across this look something like this:
Database.LeadConvert leadConvertObj = new database.LeadConvert(); leadConvertObj.setLeadId(lead.Id); leadConvertObj.setDoNotCreateOpportunity(true); //This looks like the Boolean parameter WILL NOT create an opportunity
LeadStatus convertStatus = [SELECT Id, MasterLabel
FROM LeadStatus
WHERE IsConverted = true
LIMIT 1];
leadConvertObj.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult leadConvertResult = Database.convertLead(leadConvertObj);
System.assert(leadConvertResult.isSuccess());
I want something like leadConvertObj.setCreateOpportunity();
. Please note that I want to convert the lead into a NEW opportunity.