+ Start a Discussion
VSK98VSK98 

Clone button not working in lightning but working as expected in classic

Hello All,

I am overriding the standard clone button with VF Page. In classic, it's working as expected but in lightning it's updating the same record instead of cloning the record. Please find the snippet code below.
 
<apex:page standardController="Lead" extensions="Lead_overrideCloneController" tabStyle="Lead" action="{!redirect}" lightningStylesheets="True">
    <apex:form >
        <apex:pageBlock rendered="{!okbutton}">
            <apex:pagemessages ></apex:pagemessages>
            <apex:pageBlockButtons location="Bottom">
                <apex:commandButton immediate="TRUE" action="{!okbuttonAction}" value="OK"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public with sharing class Lead_overrideCloneController {
    Public Boolean okbutton{get;set;}
    Id leadRTId;
    Id idProfileId;
    Id LeadId;
    Profile userProfile = new Profile();
    public Lead_overrideCloneController(ApexPages.StandardController controller) {
        
           
    idProfileId = UserInfo.getProfileId();
    userProfile = [Select Id, Name from Profile where Id = :idProfileId];
    LeadId= ApexPages.currentPage().getParameters().get('Id');

       
    }
    public pagereference okbuttonAction(){
      
       return null;
    }
    public pagereference redirect(){
        
        PageReference pr = ApexPages.currentPage();
        
            Map<String, String> params = pr.getParameters();
            system.debug('##### --> Sivparams'+params.keySet());
           
           String stringToAppend = '';
            for(String keyStr : params.keySet()){
                if(keyStr != 'core.apexpages.devmode.url' &&
                    keyStr != 'sfdc.override' &&
                    keyStr != 'save_new' &&
                    keyStr != 'scontrolCaching'){
                    if(stringToAppend != '') {
                        stringToAppend += '&';
                    }   
                    
                    stringToAppend += keyStr + '='+ EncodingUtil.urlEncode(params.get(keyStr),'UTF-8');
                }   
            }
          
            system.debug('##### --> Siv'+'/'+LeadId+'/e?nooverride=1&'+stringToAppend);
            return new PageReference('/'+LeadId+'/e?nooverride=1&'+stringToAppend);
            
        }
       
        
    }

Please share your thoughts....

Regards,
VSK98