Is there a way to call the existing standard action of Lead Convert inside a custom lighting component? I need to show a modal with some validations and if it seems correct by the user, click inside the modal the Convert standard action/button. Thank you!
1 Answer
There is no interface to convert a Lead directly through Lightning Components.
However you can use your Apex controller for that. Here's the example how to convert Lead programmatically (full reference in Apex Developer Guide: Converting Leads):
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.assert(lcr.isSuccess());
-
Thank you!! I have a question based on your answer, the standard mapping functionality Map Lead Fields for custom fields it's 'fired' when I call convertLead() method? If on setup of lead objet I set x custom field on the lead object to map to x custom field on the oppty object this will work?– PabloCommented Mar 25, 2020 at 14:54
-
@Pablo Yes, the standard Lead Mapping logic should retain here. Commented Mar 25, 2020 at 14:57
-