+ Start a Discussion
Prince VenkatPrince Venkat 

Lead conversion along with url change

Whenever Lead Record is Created and it is converted into opportunity. and then it should immediately change from lead page (00Q) to opportunity page URL (006) (Redirect from lead page to opportunity)

Below is my code.

Any assistance

public class LeadTriggerHandler
{
    Public static void AfterUpdate(List<Lead> lstLeads)
    {
        LeadStatus lStatus = [Select id, MasterLabel, isConverted
                                                 from LeadStatus
                                                     Where isConverted = true];
        
        List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>();
        
        for(Lead ldRecord : lstLeads)
        {
            if(ldRecord.Status == 'Closed - Converted' && ldRecord.IsConverted == false)
            {
                Database.LeadConvert lConvert = new Database.LeadConvert();
                
                    lConvert.setLeadId(ldRecord.Id);
                    lConvert.setSendNotificationEmail(true);
                    lConvert.setDoNotCreateOpportunity(false);
                    lConvert.setConvertedStatus(lStatus.MasterLabel);
                  // Add the record to the Collection..
                leadsToConvert.Add(lConvert);
            }
        }
        
        if(! leadsToConvert.isEmpty())
        {
            Database.LeadConvertResult[] results =    Database.convertLead(leadsToConvert);
        }
    }
}


Thank you
 
AbhinavAbhinav (Salesforce Developers) 
Hi Prince ,

Please check below link which has solution for Redirect to the Opportunity page after Lead is converted.

https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A8JIfSAN

Thanks!