Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

EnclosingTabId Context Wire Adapter for Lightning Experience

Returns the ID of the enclosing tab or subtab. This wire adapter is available for Lightning Web Components (LWC) only.

To determine if the component is within a tab or subtab, use this context wire adapter. If a caller component isn’t using the wire adapter inside a tab or subtab, the enclosing utility tab ID is null.

To retrieve information about the tab or the subtab that a component is rendered in, first use EnclosingTabId instead of getFocusedTabInfo(). Then call getTabInfo() and use the enclosing tab’s ID as the argument. By using EnclosingTabId, you make sure that the correct tab ID is returned when you work with lifecycle hooks such as renderedCallback() or connectedCallback().

Tip

LWC Sample Code

To get the ID of the enclosing tab in LWC, use the EnclosingTabId wire adapter.

This component retrieves the enclosing tab ID and closes the tab.

1import { LightningElement, wire } from 'lwc';
2import { EnclosingTabId, closeTab } from 'lightning/platformWorkspaceApi';
3
4export class CloseEnclosingTabExample  extends LightningElement {
5    @wire(EnclosingTabId) enclosingTabId;
6
7    handleClick() {
8        // Ensure that we have a tab open
9        if (!this.enclosingTabId) {
10            return;
11        }
12        closeTab(this.enclosingTabId);
13    }
14}

For another example that uses the EnclosingTabId wire adapter, see openSubtab().

To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.

Response

This method returns a promise that, upon success, resolves to the tabId of the enclosing tab, if within a tab. If not within a tab, this method resolves to false upon success.