Opens a subtab within a workspace tab. If the subtab is already open, the subtab is focused. This method works only in Lightning console apps.
Arguments
The method provides the same argument for both Aura Components and Lightning Web Components (LWC). However, icon, iconAlt, and label are supported only for LWC.
Name
Type
Description
parentTabId
string
The ID of the workspace tab within which the new subtab opens. You must pass the parent tab ID into the openSubtab() method.
pageReference
object
Optional. Specifies the pageReference to open.
recordId
ID
Optional. Specifies the record to open.
url
string
Optional. The URL representing the content of the new workspace tab. The URL can be either relative or absolute. To use a third-party domain, add the site as a CSP Trusted Site.
focus
boolean
Optional. Specifies whether the new subtab has focus. To display the subtab immediately, set focus to true. To open the subtab in the background, set focus to false.
icon
string
Optional. An SLDS icon key. See a full list of icon keys on the SLDS reference site. Available for LWC only.
iconAlt
string
Optional. Alternative text for the icon. Available for LWC only.
label
string
Optional. The text label for the icon. Available for LWC only.
pageReference, recordId, and url are prioritized in that order. Providing arguments with a higher priority means the others get ignored.
Note
LWC Sample Code
This component retrieves the enclosing tab ID using the EnclosingTabId wire adapter. It opens a subtab on the current tab when the handleClick() function is called. If the component doesn’t reside inside a tab or subtab, tabId is null.
To check if the current tab is a subtab, use getTabInfo(). If the current tab is a subtab, pass in the parent tab ID to the openSubtab() function.
1import{LightningElement, wire}from 'lwc';2import{EnclosingTabId, getTabInfo, openSubtab}from 'lightning/platformWorkspaceApi';34export default class OpenSubtabExample extends LightningElement{5 @wire(EnclosingTabId)tabId;67 async handleClick(){8 if(!this.tabId){9 return;10}1112 const tabInfo = await getTabInfo(this.tabId);13 const primaryTabId = tabInfo.isSubtab ? tabInfo.parentTabId : tabInfo.tabId;1415 // Open a record as a subtab of the current tab16 await openSubtab(primaryTabId, {recordId: 'YOUR_RECORD_ID', focus: true});17}18}