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
krishna chaitanya 35krishna chaitanya 35 

Need help in lightning how to override standard new page in opportunity with visualforce page

Hi All,

I have an requirement to override standard salesforce page with visualforce page in "New" button for opportunity ,it is working in salesforce classic as expected but the same is not working in lightning experience.can any one help me on this how to re-direct in lightning salesforce.
My code:
Page:
<apex:page standardController="Opportunity" extensions="MyController" action="{!redirect}"> </apex:page>

Controller:
public with sharing class MyController{

    public MyController(ApexPages.StandardController controller) {

    }

    public PageReference redirect() {
           PageReference pr = new PageReference('/006/e');
           
            pr.getParameters().put('retURL',ApexPages.currentPage().getparameters().get('retURL'));    
            pr.getParameters().put('ent',ApexPages.currentPage().getparameters().get('ent'));  
            pr.getParameters().put('nooverride','1');  
            pr.getParameters().put('opp3', 'Name_Opco_Product');
          
           return pr;
     
    }
}

Thanks in advance,
Krishna.
SandhyaSandhya (Salesforce Developers) 
krishna chaitanya 35krishna chaitanya 35
Hi Sandhya,

Thank you for the links.But in the links i didnt find any example or sample code for over riding the standard pages.If you have any sample reference please provide me.


Thanks,
Krishna.
kumar_arunkumar_arun
Hello Krishna,

To use the override standard button with the Visualforce page in the Lightning experience. You have to check which user interface is running currently. Below is sample code.
<apex:page standardController = "Opportunity">
<apex:outputPanel rendered="{! $User.UIThemeDisplayed == 'Theme3'  || $User.UIThemeDisplayed == 'Theme4d' }">
    <apex:outputText value="This is Salesforce Classic."/>
   <apex:outputText value="This is Lightning Experience."/>
    <apex:outputText value="These are multiple components wrapped by an outputPanel."/>
</apex:outputPanel>
</apex:page>
This page will work in both Salesforce Classic as well as Lightning Experience user interface.

Hope this will help you as well as others who are looking for the same.

Thanks
Arun Kumar