I want to create the custom lead conversion process where user can map the standard fields as well with the objects(Account, Contact, Opportunity) fields. In short I want to override the standard lead conversion process of salesforce along with standard lead mapping functionality.

I have created the LWC component for the same where the user can map the fields. Once after mapping I'm creating the records in the custom object named Lead_Mapping__c. Now how can i achieve the further functionality so that whatever the field mapping is selected in the page should be applied at the time of conversion? Can someone please help?

PS: Hospital is my standard object Account

Below are the screenshots for the page that I have created:

enter image description here

enter image description here

enter image description here

enter image description here

1 Answer 1


It feels like you will need to write a trigger on Lead. I would probably go for an after update and do something like this:

I would first create a map of all Account/Contact/Opportunity ids as a key and a set of lead ids as their value(in case multiple leads can be converted into the same accounts/contacts/opportunities).
Then, I would query these objects and loop through the lead mapping and the objects to find matches. Once a match is found, I would use the standard Sobject object get() and put() methods to fill in the fields.


Map<Id, Set<Id>> accToLeadMap = new Map<Id, Set<Id>>();
if (newLead.isConverted && !oldLead.isConverted) {
    if (!accToLeadMap.containsKey(newLead.ConvertedAccountId)) {
        accToLeadMap.put(newLead.ConvertedAccountId, new Set<Id>());
List<Account> accs = [SELECT Id, Name FROM Account WHERE Id IN :accToLeadMap.keySet()];
for (Lead_Mapping__c lm : yourLeadMappings) {
    for (Account a : accs) {
        if (lm.Mapping_Object__c == 'Account') {
            for (Id leadId : accToLeadMap.get(a.Id)) {
                a.put(lm.Mapping_Field__c, newLeadMap.get(leadId).get(lm.Lead_Field__c));

The code I provided shows only Account as example, you can make it more generic by using Sobject instead

  • Hello @Novarg, thank you for the solution, can you please specify what's this newLead and oldLead here? Is this a list of lead as Trigger.New and Trigger.Old? Jan 16, 2023 at 10:53
  • @AdityaDeshmukh newLead and oldLead are instances of a separate lead record before and after save. It's to make sure that we only process leads that were just converted and ignore the ones that were converted long time ago
    – Novarg
    Jan 16, 2023 at 10:58
  • Thanks, just the last doubt, what's the yourLeadMappings in for loop and newLeadMap in the last line because they are not defined? Jan 16, 2023 at 11:14
  • @AdityaDeshmukh that's literally your custom object. Make sure you query it before. And newLeadMap is Trigger.newMap
    – Novarg
    Jan 16, 2023 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .