I am using below code to open one vf page in classic mode and another page in lightning mode. But every time it is opening classic page only. Why is there any error in my code. Please help me

    <apex:page >

<script type="text/javascript">

function isLightningExperienceOrSalesforce1(){
    return((typeof sforce != 'undefined') && sforce && (!!sforce.one)); 
function popupwindow(){

        if( isLightningExperienceOrSalesforce1() ) {
        } else {

<apex:form > 
    <apex:commandButton value="Generate Report" onclick="popupwindow(this);"/>
  • Is customLightningLookup a visualforce page, where you have used Lightning Out and accessed the lightning component. If customLightningLookup is a lightning component, as far as I know, you cannot open Lightning component using a url – Hemant Jain Mar 9 '18 at 6:05
  • Hi @Hemant customLightningLookup is a visualforce page, in that i used slds for look and feel of lightning. – ApexCode Mar 9 '18 at 6:07
function inLightningExperience() {
    return 'Theme4d' === '{!$User.UIThemeDisplayed}';
function detectionOfTheme(){
        alert('Success....you are in Lex'); 
    }else {
        alert('Success....you are in Classic'); 

Its worked for me. Thank you @Tushar Sharma for you helped me a lot.

| improve this answer | |

This because in both case you are using window.open while you need to use sforce method to redirect.

if( isLightningExperienceOrSalesforce1() ) {
} else {

Navigation with the sforce.one Object

| improve this answer | |
  • No it is not working @Tushar. Did you checked that. Every time below function returning false.............................................................. function isLightningExperienceOrSalesforce1(){ return((typeof sforce != 'undefined') && sforce && (!!sforce.one)); } – ApexCode Mar 9 '18 at 6:43
  • @ApexCode how did you open the current page. You are in LEX correct. – Tushar Sharma Mar 9 '18 at 6:53
  • Yes @Tushar, when i am in Lightninig experience then also it is returning false... – ApexCode Mar 9 '18 at 6:56
  • @ApexCode how did you open the current page. – Tushar Sharma Mar 9 '18 at 6:57
  • Clicking on Switch to Lightning experience. Setup ==> Then opening Visualforce page. I was checked 'available in Lightning' checkbox also. – ApexCode Mar 9 '18 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.