+ Start a Discussion
mukesh guptamukesh gupta 

Sales console tab

I am using a lightning componet, whrn i click on a button then this coponent open. on this component i have a close button. when i click on this closed button page redirect to previous page, but tab not closed.

i am using below code for tab close
closeFocusedTab : function(component, event, helper) {
         var workspaceAPI = component.find("workspace");
        //alert(workspaceAPI);
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            //alert('aaaa -- '+response);
            var focusedTabId = response.tabId;
            workspaceAPI.closeTab({tabId: focusedTabId});
        })
        .catch(function(error) {
            console.log(error);
        });

    
    }

    Can you please suggest.

User-added image
Danish HodaDanish Hoda
Hi Mukesh, 
You can use Navigation on the close button of the other cmp.
mukesh guptamukesh gupta
I am using navigation that's working fine 
 sforce.one.navigateToSObject(component.get("v.recordId"));

but tab is not closiing 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mukesh,

Greetings to you!

You should use openTab() instead of navigateToSObject. 
var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            console.log(focusedTabId);

            //Opening New Tab
            workspaceAPI.openTab({
            recordId: '001xx000003DIkeAAG',
            focus: true
            }).then(function(response) {
                workspaceAPI.focusTab({tabId : response});
            })
            .catch(function(error) {
                console.log(error);
            });

            //Closing old one
            workspaceAPI.closeTab({tabId: focusedTabId});
        })
        .catch(function(error) {
            console.log(error);
        });

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

https://salesforce.stackexchange.com/questions/208604/how-to-open-a-custom-lightning-component-tab-app-in-lightning-service-console

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_opentab.htm

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
mukesh guptamukesh gupta
Hi Anas ,

this is a component, when i click on "Open" button  then this lightning component open with "close" and "Save"  btn. so i can't use  'workspaceAPI' when component open, Now i need to close the tab only

when i using your code i am not receive any 'response.tabId' in console log

Thanks