Managing Navigation
- A user invokes a Visualforce page, usually from the navigation menu, or from an action in the action bar.
- The Visualforce page loads and runs, including any custom controller or extension code called by the page.
- The user interacts with the page in some way: for example, to fill in some form values.
- The user submits the form, or performs some other action on the page that commits a change.
- Controller or extension code runs, saving the changes to Salesforce, and returning the results of the action.
- The Visualforce page, using JavaScript response handlers, receives the results of the action, and when successful, responds by redirecting the user to a new page that shows the results of their action.
Another common use case is simply adding links or other user interface controls to a page, which move from that Visualforce page to another page in the app. This navigation is also easily managed by the app’s navigation framework.
In these cases, navigation is handled by a special utility JavaScript object, sforce.one. The sforce.one object is automatically added to all Visualforce pages when they run inside the Salesforce mobile app. This object provides a number of functions that trigger navigation events when they run. To use these functions, you can call them directly from your page’s JavaScript code, or you can attach calls as click handlers to elements on the page.
function setupMarker(){
// Use JavaScript nav function to determine if we are
// in the Salesforce mobile app and set navigation link appropriately
var warehouseNavUrl =
'sforce.one.navigateToSObject(\'' + warehouse.Id + '\')';
// Wrap the warehouse details with the link to
// navigate to the warehouse details
var warehouseDetails =
'<a href="javascript:' + warehouseNavUrl + '">' +
warehouse.Name + '</a><br/>' +
warehouse.Street_Address__c + '<br/>' +
warehouse.City__c + '<br/>' +
warehouse.Phone__c;
// Create a panel that will appear when a marker is clicked
var infowindow = new google.maps.InfoWindow({
content: warehouseDetails
});
// ...
}
- Don’t directly manipulate the browser URL using window.location.href. This doesn’t work well with the app’s navigation management system.
- Don’t use target="_blank" in navigation URLs; you can’t open new windows inside the app.
Navigation Methods within the Canvas Framework
If you’re using Canvas, there’s a simpler way to control navigation around canvas apps and canvas personal apps in the Salesforce mobile app.
You can use Lightning Platform methods to control navigation in the app. These methods within the Canvas framework are events that reside in the JavaScript library. When you call one of the navigation methods from your canvas code, you send an event into Salesforce that reads the payload and directs the user to the specified destination.
Reference the navigation method as an event variable, with name and payload. For example:
var event = {name:"s1.createRecord", payload: {entityName: "Account", recordTypeId: "00h300000001234"}};
For more information about using the new methods, see Salesforce Mobile App Navigation Methods for Use with Canvas Apps in the Canvas Developer Guide.