Navigation and Messaging with the sforce.one Object
The sforce.one object provides the following functions. Reference the function using dotted notation from the sforce.one object. For example: sforce.one.navigateToSObject(recordId, view).
Further details of the underlying events fired by these functions can be found in the Lightning Aura Components Developer Guide.
Function | Description |
---|---|
back([refresh]) | Navigates to the previous state that’s saved in the sforce.one history. It’s equivalent to clicking a
browser’s Back button. refresh is optional. By default, the page doesn’t refresh. Pass true to refresh the page if possible. |
navigateToSObject(recordId[, view]) | Navigates to an sObject record,
specified by recordId. This record “home” has several views,
which in the Salesforce mobile app are available as slides that the user can swipe
between. view is optional and defaults to detail. view specifies the slide within record home to display initially. The possible values are as follows.
|
navigateToURL(url[, isredirect]) | Navigates to the specified URL.
Relative root and absolute URLs are supported. Relative URLs are
relative to the Lightning domain root, and retain navigation history. For example,
the relative root URL for a Visualforce page is prefixed by a forward slash, such as
/apex/c__Listen. Relative URLs like
../apex/c__Listen or apex/c__Listen are not supported. External
URLs—that is, URLs that are outside the Lightning domain—open in a separate browser
window.
Use relative URLs to navigate to different screens within your app. Use external URLs to allow the user to access a different site or app, where they can take actions that don’t need to be preserved in your app. To return to your app, the separate window that’s opened by an external URL must be closed when the user is finished with the other app. The new window has a separate history from your app, and this history is discarded when the window is closed. This also means that the user can’t click a Back button to go back to your app; the user must close the new window. mailto:, tel:, geo:, and other URL schemes are supported for launching external apps and attempt to “do the right thing.” However, support varies by mobile platform and device. mailto: and tel: are reliable, but we recommend that you test any other URLs on a range of expected devices. isredirect is optional and defaults to false. Set it to true to indicate that the new URL should replace the current one in the navigation history. When you navigate to a URL from a modal, such as from a
component that’s enabled for quick actions, the modal isn’t closed automatically by
default. To automatically close the modal when navigating, set isredirect to true.
|
navigateToFeed(subjectId, type) | Navigates to the feed of the
specified type, scoped to the subjectId. For
some feed types, the subjectId is required
but ignored. For those feed types, pass the current user’s ID as
the subjectId.
type is the feed type. The
possible values are as follows.
|
navigateToFeedItemDetail(feedItemId) | Navigates to the specific feed item, feedItemId, and any associated comments. |
navigateToRelatedList(relatedListId, parentRecordId) | Navigates to a related list for
the parentRecordId. For example, to display a related list for a
Warehouse object, the parentRecordId is Warehouse__c.Id. relatedListId is the API name or ID of the related list to display. |
navigateToList(listViewId, listViewName, scope) | Navigates to the list view that’s
specified by the listViewId, which is the ID of the list view to
be displayed. listViewName sets the title for the list view. It doesn’t need to match the actual name that’s saved for the list view. To use the saved name, set listViewName to null. Set scope to the name of the sObject in the view, for example, “Account” or “MyObject__c”. |
createRecord(entityName[, recordTypeId][, defaultFieldValues]) | Opens the page to create a record
for the specified entityName, for example, “Account” or
“MyObject__c”. recordTypeId is optional and specifies the record type for the created object. Calling createRecord without providing a recordTypeId may result in an error. defaultFieldValues is optional and, if provided, prepopulates fields on a record create panel, including fields not displayed on the panel. Users must have create access to fields with prepopulated values. Errors during saving that are caused by field access limitations don’t display error messages. |
editRecord(recordId) | Opens the page to edit the record specified by recordId. |
showToast({toastParams}) | Shows a toast. A toast displays a message
below the header at the top of a view. The toastParams object sets the attributes for the toast. Use any attribute
available for the force:showToast Aura event. For
example:
|
publish(messageChannel, message) | Publishes a message to a messageChannel using Lightning Message Service. See Publish on a Message Channel. |
subscribe(messageChannel, function) | Subscribes to a messageChannel using Lightning Message Service. The function provided runs when a message on the subscribing message channel is published. The subscribe() function returns a subscription object that can be used with unsubscribe(). See Subscribe and Unsubscribe from a Message Channel. |
unsubscribe(subscription) | Unsubscribes a subscription object from a message channel. See Subscribe and Unsubscribe from a Message Channel. |
- Calls to sforce.one.navigateToURL may result in an “Unsupported Page” error if the URL references standard pages for objects or Chatter pages. To avoid this error, ensure that the URL begins with a forward slash (/_ui instead of _ui).
- The sforce.one.createRecord method doesn’t respect Visualforce overrides on the standard action.
- Developers can use the pageReference class to control navigation for the Salesforce mobile app. Some actions and their associated pageReference URLs are not yet fully supported. For example, standard_recordPage with actions clone or edit may not work as expected. Full support is planned for future releases.