+ Start a Discussion
louisa barrett 7louisa barrett 7 

Lightning Console close workspace and sub tabs

Does anyone know how to close a workspace(primary) tab and it's sub tabs?
The below only returns the subtab. I need to close the primary and any subtabs.
var workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
                    var enclosingTabId = tabId;
                    workspaceAPI.closeTab({tabId: enclosingTabId});
Many thanks
Khan AnasKhan Anas (Salesforce Developers) 
Hi Louisa,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.



I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
louisa barrett 7louisa barrett 7

Thank you for the response, but that is using the .getAllTabsInfo method and closing all the tabs regardless of whether they are workspace or subtabs. I need to find the workspace ID of the currently focused subtab. In Classic there was a specific method for this .getEnclosingPrimaryTabId, but I cannot see any equivilent method to that in the WorkspaceAPI

Khan AnasKhan Anas (Salesforce Developers) 
The below component has a button that, when pressed, closes the currently focused tab. It closes a workspace tab or subtab.

<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <lightning:workspaceAPI aura:id="workspace"/>
    <lightning:button label="Close Focused Tab" onclick="{!c.closeFocusedTab}"/>

    closeFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.closeTab({tabId: focusedTabId});
        .catch(function(error) {

I hope it helps you.

Khan Anas
louisa barrett 7louisa barrett 7
I tried that to begin with, but if the currently focused tab is a sub tab that's what it closes, not the workspace tab.
I can't focus the workspace tab and then call that methosd, as I cannot find a way to get the ID for it in the first place.