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.

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

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

({
    handleGetEnclosingTabId : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getEnclosingTabId().then(function(tabId) {
            console.log(tabId);
       })
        .catch(function(error) {
            console.log(error);
        });
    }
})

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.