[SalesForce] Salesforce1 navigateToURL method

I have a VisualForce page that has navigation which will return users to various views in the Salesforce native interface such as the Home tab, or to specific SObject records.

I have found that if I use window.open('/', '_self') then the user is always taken back to the desktop version of Salesforce even if they are using the Salesforce1 app.

To stop this happening, I am refactoring those bits of code to something like the following:

if(typeof sforce !== "undefined" && sforce !== null) {
    // Salesforce1 navigation
    sforce.one.navigateToSObject(accountId);
} else {
    // Desktop navigation
    window.open('/'+accountId, '_self');
}

The above code using the navigateToSObject() method works fine, but if I try to use to navigateToSObject() method to return the user to the home page, then I get a:

The page you are trying to access is not supported on mobile devices

error.

I have tried all of the following and got the same error:

sforce.one.navigateToURL('/');
sforce.one.navigateToURL('/one/one.app');
sforce.one.navigateToURL('https://emea.salesforce.com/one/one.app');
sforce.one.navigateToURL('/001/e'); // I know this is not the home page

I'm not aware that I can make the home page accessible to mobile devices in the same way that I could make a visualforce page accessible. I would have thought that this is automatic.

I'd like to ask how other people would implement this and if there is anything that people can see that I am doing wrong here.

Thanks

Best Answer

So the way this works is a bit different based on your org, but this should work for you.

sforce.one.navigateToURL("/home/home.jsp");

If that doesn't work for you, when you log in to salesforce without S1, copy the url (relative url should be fine) and use that.

We (currently) get that url and map it to the default component you see. This also means you'll get the back button. Based on what I'm seeing in the code, we don't really provide you a way to go to you back to start (/one/one.app).

Related Topic