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 addresses Lightning Experience shows in the browser, so you can predict where a link goes, build links by hand, and spot common mistakes.
Why URLs matter
Every list view and record page in Lightning Experience has its own address. That address lets you bookmark a view, send a colleague a link, or check where a button in a custom component sends users. Developers also use the same patterns when they navigate from code, which the next chapter covers.
Lightning URLs are readable. Once you know the pattern, you can tell what a link opens without clicking it.
The two patterns you will see most
The following two URLs open an Account list view and a single Account record.
/lightning/o/Account/list?filterName=Recent
/lightning/r/Account/001XXXXXXXXXXXXXXX/viewThe first URL opens the Account list view named Recent. The second opens the view page of a single Account record. Here, 001XXXXXXXXXXXXXXX stands for a real record Id.
In a browser the full address starts with your org's domain, such as https://yourdomain.lightning.force.com. The examples above show only the path, which is the part that follows the domain.
Anatomy of a Lightning URL
Each part of the path has a job.
| Part | Example | Meaning |
|---|---|---|
| `/lightning` | `/lightning` | Marks the address as Lightning Experience |
| Page kind | `o` or `r` | `o` is an object page. `r` is a record page. |
| Object API name | `Account` | The API name of the object, not its label |
| Record Id or action | `001...` or `list` | A record Id for record pages, or an action for object pages |
| Action | `view` | What to do with the record |
| Query string | `?filterName=Recent` | Extra state, such as which list view to show |
Object pages: `/lightning/o/`
The letter o stands for object. The pattern is:
/lightning/o/<ObjectApiName>/<action>Common actions are home, which opens the object home page, list, which opens a list view, and new, which opens the form for a new record.
/lightning/o/Account/homeopens the Account object home page./lightning/o/Account/listopens the last list view you used for Accounts./lightning/o/Account/newopens the new Account form.
For custom objects, use the API name, which ends in __c. For example, /lightning/o/Project__c/list.
Record pages: `/lightning/r/`
The letter r stands for record. The pattern is:
/lightning/r/<ObjectApiName>/<RecordId>/<action>The usual action is view, which shows the record page. Another is edit, which opens the edit form. Related lists have their own page. For example, /lightning/r/Account/001XXXXXXXXXXXXXXX/related/Contacts/view opens the full Contacts related list for that Account.
Salesforce also accepts a shorter form with no object name, such as /lightning/r/001XXXXXXXXXXXXXXX/view. The Id prefix tells Salesforce which object the record belongs to. Including the object name is clearer to read and is the form Lightning itself generates.
Reading the query string
The text after ? carries state. For list views, the main parameter is filterName.
/lightning/o/Account/list?filterName=RecentThe value can be one of two things:
- The API name of a list view, such as
AllAccountsorMyAccounts. Standard list views have predictable names. - The 15 or 18 character Id of a list view, which is how you point to a list view you or an administrator created. The Id begins with
00B.
Use Recent to open the built-in Recently Viewed list. If filterName does not match any list view you can access, Lightning falls back to a default view instead of showing an error.
What a list view is really asking
A list view is a saved filter plus a sort order and a set of columns. The following SOQL query returns the same rows as a list view that filters Accounts by Industry and sorts them by Name.
SELECT Id, Name, Industry
FROM Account
WHERE Industry = 'Technology'
ORDER BY NameThe WHERE clause matches the list view filter, and ORDER BY matches its sort. The columns you see in the table correspond to the fields in SELECT. Keep this in mind when a link opens a list that looks different from what a colleague sees. The list view's filter, the sharing rules that limit which records you can see, and your field-level security can each change the result, even when the URL is identical.
Some URLs depend on your session
Not every Lightning URL is portable. Some patterns work for anyone who can access the target, and others depend on the person opening them.
| URL | Works for everyone with access? | Notes |
|---|---|---|
| `/lightning/r/Account/<Id>/view` | Yes | Fails if the user cannot see the record |
| `/lightning/o/Account/list?filterName=<Id>` | Mostly | The list view must be shared with the user |
| `/lightning/o/Account/list` | Varies | Opens the last view that user used |
| `/lightning/page/home` | Yes | Opens the Home page of the current app |
Because the app is not part of the URL for these patterns, Lightning chooses an app when the page loads. Usually it keeps the app you are already in. If you open a link from outside Salesforce, such as from email, Lightning uses your last used app. When that app does not include the object as a navigation item, the page still opens, but the navigation bar may not highlight an item.
How URLs relate to navigation
The URL pattern shows a path through the model from earlier chapters:
placeholderThe diagram below summarizes how the pieces connect.
Clicking a row in a list view moves you from an o URL to an r URL. Using the browser's back button returns you to the o URL, and Lightning restores the list view.
Reading a URL step by step
Suppose a colleague sends you this link:
/lightning/o/Opportunity/list?filterName=00BXXXXXXXXXXXXXXX/lightningmeans Lightning Experience.omeans an object page, so this is not a single record.Opportunityis the object.listmeans a list view is shown.filterName=00B...points to one specific list view by Id. The00Bprefix confirms it is a list view Id.
You now know the link opens a custom or saved Opportunity list view, and that you need access to that list view to see the same result.
Common errors
- Using the label instead of the API name.
/lightning/o/Project/listfails for a custom object namedProject__c. Use the API name. - Wrong case or typo in the object name. Standard object names are case-sensitive in practice, so use
Accountand notaccount. - Copying a record Id from another org. Ids differ between sandboxes and production, so a link copied from one org does not work in another.
- Assuming a list view link works for everyone. An unshared list view Id gives a fallback view or an access error.
- Hardcoding the domain. The domain differs between orgs and between sandbox and production. Use relative paths in links you build, and do not paste a full address into code.
- Building URLs in code when navigation APIs exist. Hand-built strings break when Salesforce changes URL formats. The next chapter shows the supported way.
Try it yourself
- Open an Account record in your org and look at the address bar.
- Identify the object API name and the record Id.
- Change the end of the path from
viewtoeditand press Enter. The edit form opens. - Replace the whole path with
/lightning/o/Account/list?filterName=Recentand press Enter. - Open the list view drop-down, pick another view, and watch how
filterNamechanges in the address bar.
Summary
Lightning URLs follow two main patterns. Object pages use /lightning/o/<Object>/<action>, and record pages use /lightning/r/<Object>/<Id>/<action>. Query parameters such as filterName select the list view to show. The link alone does not guarantee what a user sees, because sharing, list view access, and field security all apply.
Exercise
What does each part of this URL mean? /lightning/o/Contact/list?filterName=Recent
Show answer
/lightning marks Lightning Experience. o means an object page. Contact is the object API name. list is the action that shows a list view. filterName=Recent selects the built-in Recently Viewed list view.
Exercise
A colleague sends you /lightning/r/Invoice__c/a01XXXXXXXXXXXXXXX/view, but you get an error. Name two likely causes.
Show answer
You may lack access to the record because of sharing rules or profile permissions. The Id may also come from another org, such as a sandbox, so it does not exist in your org. A third possibility is that the object is not available to you at all.
Exercise
How would you write a link that opens the new Opportunity form?
Show answer
/lightning/o/Opportunity/new