function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sflearningsflearning 

Trigger to auto convert lead in lightning to Account, contact and opportunity upon clicking Convert button

Here is the trigger which auto convert the trigger uplon creation...
i want to update it ..when clicking on convert button in lightning...New Account gets created /merge in existing account, similarly in case of contact and opportunity should happen....
Any help over this...
thanks 

trigger Leadconvert on Lead (after insert, after update) {
    for (Lead lead : Trigger.new) {
      if (lead.isConverted == false) //to prevent recursion
      {
       
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(lead.Id);
       
        String oppName =  lead.Name;
        lc.setOpportunityName(oppName);
       
        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());
       
             
    }
  }
}