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
tulasi ram 1tulasi ram 1 

sforce.one is not working in navigation from visualforce pages

I am using below code to navigate to different pages based on user is in lightning or classic. But every time return((typeof sforce != 'undefined') && sforce && (!!sforce.one)); is returning FALSE either in Lightning or Classic . Please help me in this
<apex:page >

<script type="text/javascript">

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

        if( isLightningExperienceOrSalesforce1() ) {
            window.open('/apex/customLightningLookup');
        } else {
            window.open('/apex/testVFpage'); 
        }
     }
</script>

<apex:form > 
    <apex:commandButton value="Generate Report" onclick="popupwindow(this);"/>
</apex:form> 
</apex:page>

 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Tulasi,

Make sure your visualforce is available for Lightning experience as mentioned in the following link: https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/vf_pages_where_accessible_from.htm?search_text=sforce.one

"Be sure to select Available for Lightning Experience, Lightning Communities, and the mobile app for all pages in a multi-page process."

Furthermore, Salesforce has another approach to detect which interface the user is using. Try using it instead of relying on the sforce object: https://developer.salesforce.com/blogs/isv/2016/04/introducing-ui-theme-detection-for-lightning-experience.html

​Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.