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.

getEnclosingTabId() for Lightning Experience

Returns the ID of the enclosing tab. This method isn’t supported for Lightning Web Components (LWC).

To retrieve the enclosing tab ID with LWC, see EnclosingTabId context wire adapter.

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

Tip

Arguments

None.

Aura Components Sample Code

This component has a button that, when clicked, retrieves the enclosing tab ID.

This is the component code. The lightning:workspaceAPI component provides access to Lightning console methods. When clicked, the lightning:button base component executes the handleGetEnclosingTabId action in the component’s client-side controller.

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <lightning:workspaceAPI aura:id="workspace" />
3    <lightning:button label="Get Enclosing Tab Id" onclick="{! c.handleGetEnclosingTabId }" />
4</aura:component>

This is the controller code. The handleGetEnclosingTabId action returns the ID of the enclosing workspace tab.

1({
2    handleGetEnclosingTabId : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.getEnclosingTabId().then(function(tabId) {
5            console.log(tabId);
6       })
7        .catch(function(error) {
8            console.log(error);
9        });
10    }
11})

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, the method resolves to false upon success.