4

I'm trying to use the Salesforce documented method for determining if we're in the Salesforce1 UI when viewing a page in my app but for some reason, this code is not working the browser version of Salesforce (one/one.app)

if( (typeof sforce != 'undefined') && (sforce != null) ) {
    // Salesforce1 navigation
    sforce.one.navigateToSObject(aId);
} 

sforce is not defined in /one/one.app ... Any ideas?

2
  • I assume your running that code in a VF page embedded in S1 right?
    – Kris Gray
    Commented Jul 17, 2014 at 0:14
  • Also your check is a little off, it should be && sforce.one != null) )
    – Kris Gray
    Commented Jul 17, 2014 at 0:14

2 Answers 2

1

Just guessing by the docs :

Are you trying to run the app in your browser : may be this could be the reason why it is not working

http://www.salesforce.com/us/developer/docs/salesforce1/index_Left.htm#CSHID=vf_dev_best_practices_pages_multipurpose.htm|StartTopic=Content%2Fvf_dev_best_practices_pages_multipurpose.htm|SkinName=webhelp

The if statement checks to see if the sforce object is available and usable. This is only true if the page is running inside Salesforce1.

If the sforce object isn’t available, trying to use it to navigate anywhere results in a JavaScript error, and no navigation

5
  • Salesforce1 is both a browser app (one/one.app) and a native mobile app, so I would expect the Javascript API to be available in both places.
    – greenstork
    Commented Apr 17, 2014 at 22:48
  • how are you trying to access you app on the browser are you using instance/one/one.app
    – Rao
    Commented Apr 17, 2014 at 22:56
  • 1
    did you enable saleseforce1 app access on desktop. check out : jessealtman.com/2013/12/working-with-salesforce1-on-the-desktop
    – Rao
    Commented Apr 17, 2014 at 22:58
  • that's correct (/one/one.app), the browser container for Salesforce1
    – greenstork
    Commented Apr 17, 2014 at 22:58
  • I'm clearly inside of Salesforce1 visual container, it has been enabled on the desktop.
    – greenstork
    Commented Apr 17, 2014 at 22:59
0

The reason why I wasn't able to find sforce in my console was because the Visualforce page is inside of an iframe. I needed to change the context of the console to operate from the frame rather than the top frame in Chrome

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .