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
trailhead solutions 10trailhead solutions 10 

Standard button Override -- Code to be change for lightning version


I have added apex class and VF Page to override standard convert button to Accept Button. The mentioned below code is working fine. But it is getting converted in Classic Version. But need the lead Conversion Page in Lightning Version. Anyone Please suggest.

public class AutoConvertLeads {
    private final Lead lead; //variable for the standard Lead object
    public AutoConvertLeads(ApexPages.StandardController standardPageController) {
        this.lead = (Lead)standardPageController.getRecord(); //initialize the standard controller
    public PageReference redirectToConvertionPage() {
        PageReference nextPage = new PageReference('/lead/leadconvert.jsp'); //set the starting point for the page reference to which the User will be sent
        nextPage = encodeAndSetParam(nextPage, 'retURL', lead.Id); //set the retURL parameter in order to allow for returning to Lead if User cancels from page
        nextPage = encodeAndSetParam(nextPage, 'id', lead.Id); //set the id parameter so that the conversion page knows the proper record
        nextPage = encodeAndSetParam(nextPage, 'nooppti', '1'); //set the nooppti parameter to pre-populate the "Do not create a new opportunity upon conversion." checkbox
        nextPage = encodeAndSetParam(nextPage, 'nooverride', '1'); //set the nooverride parameter in order to prevent looping in the user interface
        nextPage.setRedirect(true); //indicate that the redirect should be performed on the client side
        return nextPage; //send the User to the Lead conversion page
    public PageReference encodeAndSetParam(PageReference passedPageReference, String passedParameterId, String passedParameterValue){
        if (passedParameterValue != null) { //if the passedParameterValue is not null
            String encodedParameterValue = EncodingUtil.urlEncode(passedParameterValue, 'UTF-8'); //encode the value that was passed to eliminate conflicts with unsafe characters
            passedPageReference.getParameters().put(passedParameterId, EncodingUtil.urlDecode(encodedParameterValue, 'UTF-8')); //add the parameter to the page reference
        return passedPageReference;


Visual Force Page:

<apex:page action="{!redirectToConvertionPage}" extensions="AutoConvertLeads" standardController="Lead">
    <apex:sectionHeader title="Accept" subtitle="{!Lead.Name}" help="/htviewhelpdoc?id=leads_convert.htm&siteLang=en_US"></apex:sectionHeader>
    <apex:pageMessages ></apex:pageMessages>


ShirishaShirisha (Salesforce Developers) 


Can you please confirm,if there is any error while trying to click on the button which you have overriden.The same code should work for the Lightning sa well since there is no JavaScript code has been used in VF page.

Also,make sure that you have selected the checkbox "Use Salesforce Classic Override" for the Lightning Experience Override as well.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
trailhead solutions 10trailhead solutions 10
Hi Shirisha

No Error in the code and button Shirisha. Its working Perfect. May I know where that checkbox you mentioned should find? Please help in this to achieve.

Please find the link below for "Override Standard Buttons and Tab Home Pages":