Activity Forums Salesforce® Discussions Salesforce1 or sforce.one.navigateToSobject not working in mobile?

  • Manpreet

    Member
    April 26, 2018 at 5:26 pm

    Hi shubham,

    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

    # 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
    unction 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>

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos