+ Start a Discussion
Yamini BathulaYamini Bathula 

Lead Conversion in Lightning

Hi Guys,

We have moved to Lightning recently. The issue is now with Lead Conversion. In lightning if users dont enter Opportunity name in conversion window then the Opporutnity is not created. So we wanted to automate opp creation if the user has missed populating the Opporutniy Name field. 
I wrote trigger for that and it is working fine. But the only issue is the newly created opporutnity  doesnt have any lead fields mapped from Lead as the standard Lead conversion do.

Soes nay one have any idea of how to achieve the Lead Field mapping in the trigger instead of writing assignment statements in the trigger?

Thanks,
Here is my trigger:
 
trigger LeadConversionOppCreation on Lead (after update) 
{
 if (Trigger.new.size() == 1) 
 {

    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true)
    {
         if (Trigger.new[0].ConvertedAccountId != null) 
         {
              Account a = [Select a.Id, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
              
              if (Trigger.new[0].ConvertedOpportunityId == null) 
                { 
                 Opportunity opp = new Opportunity();
                 opp.Name= Trigger.new[0].Trading_Name__c;
                 opp.StageName = 'Qualification' ;  
                 opp.CloseDate =  Date.today() + 14; 
                 opp.AccountId =  Trigger.new[0].ConvertedAccountId;
               /* I have commented out the assignment statements for now. If I go with this way then every time a new field is added on to a lead then I have to update the trigger if we have to map it across to opportunity from Lead.
               opp.Xero_Payments__c =  Trigger.new[0].Xero_Accept_Payments__c; 
                 opp.API_Requested__c = Trigger.new[0].API_Requested__c;
                 opp.Avg_Trans_Value__c = Trigger.new[0].Avg_Trans_Amount__c;
                 opp.BPAY_Required__c = Trigger.new[0].BPAY_Requested__c;  
                 opp.Console_Gateway__c = Trigger.new[0].Console_Gateway__c;
                 opp.Lead_Countries__c = Trigger.new[0].Lead_Countries__c;
                 opp.Current_Processor__c =  Trigger.new[0].CurrentProcessor__c;
                 opp.Recurring_Required__c = Trigger.new[0].Direct_Debit_Requested__c;
                 opp.Real_Time_Required__c = Trigger.new[0].eCommerce__c;
                 opp.HPP_Requested__c = Trigger.new[0].HPP_Requested__c;
                 opp.Lead_Created_Date_and_Time__c = Trigger.new[0].  */
                     
                 insert opp;
                   
                    
                }
         }    
    }
 }    
}

 
Best Answer chosen by Yamini Bathula
Yamini BathulaYamini Bathula
Hi Guys,

Just an Update on this. I found a work around for this. If any one has the same issue they can try this work around.A Validation Rule on Leads to Check the COnverted Opporutnity ID for null Value can force the user to enter name in the Opportunity Name field. This way we can make sure an Opportunity is created in Lead Conversion.
Here is the link explaining how to do this : https://www.shellblack.com/administration/enforce-opportunity-creation-on-lead-conversion/

Validation Rule Formula on Leads:
AND(IsConverted=true, ConvertedOpportunityId="") .

Thanks,
Yamini.