Sub topic 13
Reading Lightning URLs
This chapter assumes you know what an object, record, and field are, and that you can open an Account list view and a record page in Lightning Experience. Here you will learn to read the address bar so you can tell where you are, build links by hand, and understand what developers target when they navigate from code.
Why URLs matter
Every list view and record page in Lightning Experience has its own URL. You can bookmark one, paste it into a chat message, or use it in a link on a page. A URL follows a fixed pattern, so you can read it and predict where it leads.
The anatomy of a Lightning URL
The two patterns you will see most often are the list view URL and the record page URL.
/lightning/o/Account/list?filterName=Recent
/lightning/r/Account/001XXXXXXXXXXXXXXX/viewIn these examples, 001XXXXXXXXXXXXXXX stands for a real record Id.
The first URL opens the Account list view named Recent. The second opens the view page of a single Account record.
| Part | Meaning |
|---|---|
| `/lightning` | The Lightning Experience prefix. |
| `/o/` | The path points to an object page, such as an object home or list view. |
| `/r/` | The path points to a record. |
| `Account` | The API name of the object. |
| `list` | The action: show a list view. |
| `001XXXXXXXXXXXXXXX` | The Id of the record. |
| `view` | The action: show the record page in view mode. |
| `?filterName=Recent` | A query parameter that picks the list view. |
Record Ids start with a prefix that identifies the object. Account Ids start with 001, which is why the example looks the way it does.
The filterName parameter
The filterName value selects which list view appears. Built-in views such as Recent use a name. Views you create have an Id instead, so a link to your own view looks like ?filterName=00B.... The Id is easiest to copy from the address bar after you open the view.
A list view is a saved set of filters and sorting. The Account list view that filters by Industry and sorts by Name returns the same rows as this query:
SELECT Id, Name, Industry
FROM Account
WHERE Industry = 'Technology'
ORDER BY NameThe URL only names the view. Salesforce applies the saved filters and sorting when the page loads.
Using URLs in practice
- Bookmark a list view you open often, then open it without going through the App Launcher.
- Share a record link with a colleague. They see the record only if their access allows it.
- Change the object name in a URL you know, for example from
AccounttoContact, to reach the matching page for another object.
From URL to code
A developer does not need to build URL strings by hand. A Lightning Web Component can describe the destination, and the platform builds the URL. The NavigationMixin takes a page reference with a type, attributes, and optional state.
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class AccountNavigator extends NavigationMixin(LightningElement) {
openRecentAccounts() {
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Account',
actionName: 'list'
},
state: {
filterName: 'Recent'
}
});
}
openAccount(recordId) {
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: recordId,
objectApiName: 'Account',
actionName: 'view'
}
});
}
}The pieces match the URL. objectApiName is the object, actionName is list or view, and state.filterName is the query parameter. standard__objectPage produces an /o/ URL, and standard__recordPage produces an /r/ URL.
Common errors
- "URL No Longer Exists" page. The record was deleted or the Id is wrong.
- Insufficient privileges. The record exists, but your user cannot see it.
- Wrong list view opens. The
filterNamevalue is misspelled or refers to a view you cannot access. - Links copied from Salesforce Classic. Classic URLs use a different format and do not follow the
/lightning/patterns.
Exercise
A colleague sends you /lightning/r/Contact/003XXXXXXXXXXXXXXX/view. What object and action does it name, and which type would you use in a page reference to reach the same place from a Lightning Web Component?
Show answer
The object is Contact and the action is view. The /r/ segment means a record page, so the page reference type is standard__recordPage, with objectApiName: 'Contact', actionName: 'view', and the record Id in recordId.
Exercise
What URL would open the Contact list view named Recent?
Show answer
/lightning/o/Contact/list?filterName=Recent