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?

  • I assume your running that code in a VF page embedded in S1 right? – Kris Gray Jul 17 '14 at 0:14
  • Also your check is a little off, it should be && sforce.one != null) ) – Kris Gray Jul 17 '14 at 0:14
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

  • 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 Apr 17 '14 at 22:48
  • how are you trying to access you app on the browser are you using instance/one/one.app – Rao Apr 17 '14 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 Apr 17 '14 at 22:58
  • that's correct (/one/one.app), the browser container for Salesforce1 – greenstork Apr 17 '14 at 22:58
  • I'm clearly inside of Salesforce1 visual container, it has been enabled on the desktop. – greenstork Apr 17 '14 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.