+ Start a Discussion
Michael_TorchedloMichael_Torchedlo 

Salesforce1 mobile navigation, sforce.one not working

I've been reading through the documentation about using the sforce.one javascript library but I can't seem to get a simple hyperlink or output link to properly work in Salesforce1.  If anyone in the community can please clarify where my error is, it is much appreciated.

The page renders properly in the mobile app, but the links do nothing (no error message, no screen change).

As a novice, I thought it may be just a syntax problem, so I tried several variations below.
 
<apex:page docType="html-5.0" showheader="false" sidebar="false" > 
    <div style="width:100%;" >
    <apex:form rendered="true" id="theform" >
    
    <apex:outputLink value="javascript:sforce.one.navigateToSObject(001e000000Ysn5I);" >
          <apex:outputText value="LINK 1" />
    </apex:outputLink><br/><br/>
    
    <apex:outputLink value="javascript:sforce.one.navigateToSObject('001e000000Ysn5I');"  >
          <apex:outputText value="LINK 2" />
    </apex:outputLink><br/><br/>

    <apex:outputLink value="javascript:sforce.one.navigateToURL('/001e000000Ysn5I');"  >
          <apex:outputText value="LINK 3" />
    </apex:outputLink><br/><br/>
    
    <apex:outputLink value="javascript:sforce.one.navigateToURL(/001e000000Ysn5I);"  >
          <apex:outputText value="LINK 4" />
    </apex:outputLink><br/><br/>        
        
    </apex:form>
    </div>
</apex:page>


 
Best Answer chosen by Michael_Torchedlo
bob_buzzardbob_buzzard
That's odd - it implies the page doesn't think its running inside Salesforce1.  How are you opening the page?

All Answers

bob_buzzardbob_buzzard
I wouldn't expect your first and fourth to work as those aren't string literals.  I would expect the second link to work.  The way I'd investigate this is to access via the '/one/one.app' URL in a desktop browser, and use the browsers inspector/console log to see if you get an error when you click on the link.
Michael_TorchedloMichael_Torchedlo
Bob, thanks for your reply.  I removed 1 and 4.  I do use the '/one/one.app'.  The error message I get is "Uncaught ReferenceError: sforce is not defined".  
bob_buzzardbob_buzzard
That's odd - it implies the page doesn't think its running inside Salesforce1.  How are you opening the page?
This was selected as the best answer
Michael_TorchedloMichael_Torchedlo
The problem was not this page, but how I got to the page.  
I had used <apex:commandButton onclick="window.location='/apex/pagename';return false;" /> to navigate to the page in the first place.  This renders inside within Salesforce1 app window, but apparently it does not open the page using the Salesforce1 app browser, so it was reading the page as though it was opening in full browser (no SF1 functions).  
bob_buzzardbob_buzzard
Yeah, that will open an inappbrowser in cordova parlance, and the Salesforce1 JavaScript isn't available inside that. I went into this in a bit more detail in a blog post a while ago if you are interested:

http://bobbuzzard.blogspot.co.uk/2014/01/visualforce-in-salesforce1.html