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
Tim Miller 26Tim Miller 26 

Visualforce Override button redirect to a lightning app

We have users in both Classic and Lightning using the standard "New" button on leads.  I need to override the standard "New" button and redirect the user to a lightning app.  I created a VF page action that will redirect the user to the lightning app.  Everything works great however for lightning users, the redirect opens a new tab in the browser.  How do I keep the redirect on the same browser window in lightning?  Do I need to create a VF page pulling in a lightning component?
Best Answer chosen by Tim Miller 26
karthikeyan perumalkarthikeyan perumal
Hello Tim, 

while redirect to lightining app you have make client call  not from server side. 

use below updated code. kinldy check and let me know  if its works. 
 
<apex:page standardController="Lead"  sidebar="true"  tabstyle="Lead">
 
 <script type="text/javascript">
   window.onload = function(){ 
   
   var Themstr= "{! $User.UIThemeDisplayed }";    
   if(Themstr == "Theme4d")
   {
   window.location = '/c/LeadSearchApp.app?src=Lead&type=lex';
   }
   else
   {
    window.location.href = '/c/LeadSearchApp.app?src=Lead&type=cla';
   }     
}
</script>
 
</apex:page>


Hope this will help you.  Mark it solved if its works for you.

Thanks
karthik
 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello, 

in your VF page you are using any Javascript code to  navigate  user. kinldy post your code. 

Thanks
karthik
 
Tim Miller 26Tim Miller 26
Hi karthik,

my VF Page does not use any javascript code it is all done on the VF page action wich calls the action pagereference method on the controller.
Tim Miller 26Tim Miller 26
Hi Karthik, I am not using javascript in a visualforce page. The VF Page just uses an action method call to the controller pageReference.
karthikeyan perumalkarthikeyan perumal
if possible could post your VF page and controller code?

Thanks
 
Tim Miller 26Tim Miller 26
My VF Page:

<apex:page standardController="Lead" extensions="LeadExtension" sidebar="true" tabstyle="Lead" action="{!Action}">
</apex:page>

My Class:
public with sharing class LeadExtension {
        public PageReference Action(){ 
             string str = UserInfo.getUiThemeDisplayed();
             if(str == 'Theme4d'){
                return new PageReference('/c/LeadSearchApp.app?src=Lead&type=lex');       
             }else{
                return new PageReference('/c/LeadSearchApp.app?src=Lead&type=cla');     
             }                   
       }
}
 
karthikeyan perumalkarthikeyan perumal
Hello Tim, 

while redirect to lightining app you have make client call  not from server side. 

use below updated code. kinldy check and let me know  if its works. 
 
<apex:page standardController="Lead"  sidebar="true"  tabstyle="Lead">
 
 <script type="text/javascript">
   window.onload = function(){ 
   
   var Themstr= "{! $User.UIThemeDisplayed }";    
   if(Themstr == "Theme4d")
   {
   window.location = '/c/LeadSearchApp.app?src=Lead&type=lex';
   }
   else
   {
    window.location.href = '/c/LeadSearchApp.app?src=Lead&type=cla';
   }     
}
</script>
 
</apex:page>


Hope this will help you.  Mark it solved if its works for you.

Thanks
karthik
 
This was selected as the best answer
Tim Miller 26Tim Miller 26
Hi Karthik, the redirect for the lightning page works perfect however the link for classic gets stuck loading my VF Page
Any suggestions for getting that to go through?
Suma G 7Suma G 7
Hi,
i am new  to lighting pages. we have both lightning & classic users for our application,and i am overriding the new button on case object, in lightning view new button will open lightning page and in classic view it should open std. case new page. now lightning page is opening for both. any suggetions on this. 

Thanks in advance!
-Suma