Salesforce1 or sforce.one.navigateToSobject not working in mobile

Salesforce1 Jan 29, 2016

Use case

While working with Visualforce Page for Salesforce1 mobile following unexpected behavior will be expected

  • Navigation to Browser/New Tab
  • Deviation from Salesforce1 App
  • Navigation to standard detail/view page but not Salesforce1 View

Fix

In order to fix this issue please check following points are coded in Visuaforce page

  • Check for <meta> tag, if meta tag not there it won't work on mobile
<head>
   <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
</head>
  • Include Apex.js for loading Salesforce1 libraries
<apex:includeScript value="/soap/ajax/32.0/apex.js"/>
  • Javascript function to identify mobile/desktop
function navigateTo(sObjectId) {
    if ((typeof sforce != 'undefined') && sforce && (!!sforce.one)){
        // Salesforce1 navigation                 
        sforce.one.navigateToSObject(sObjectId, 'detail');
    } else {
        // Set the window's URL using a Visualforce expression
        window.location.href = '{!$site.Prefix}' + '/' + sObjectId;
// site prefix helps when navigation in community
    }
}

Invoking js function

Pass object Id for <a> tag or some button like shown below,
<a href="#" onClick="navigateTo('{!sOjbectId}');">Click Here</a>

Hopefully this should fix your problem!

If still problem exists you can comment below

Phanindra Mangipudi

Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap