function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.

https://ericsplayground.wordpress.com/2018/08/11/close-all-tabs-in-a-lightning-console/

https://github.com/ericrsmith35/Lightning-Components/tree/master/src/aura/ersCloseConsoleTabs

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
Hi,

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

Thanks
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.

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

Controller:
({
    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) {
            console.log(error);
        });
    }
})

I hope it helps you.

Regards,
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.