[SalesForce] How to open a custom Lightning component/tab/app in Lightning Service Console

How to open a Lightning open a custom Lightning component/tab/app in Lightning service console

As per doc tab can be opened using console workspace API. But what will be URL for a custom Lightning Component/app/tab.

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


({
openTab : function(component, event, helper) {
    var workspaceAPI = component.find("workspace");
    workspaceAPI.openTab({
        **url: "#/sObject/500R0000000myfGIAQ/view",**        
        focus: true
    }).then(function(response) {
        workspaceAPI.getTabInfo({
            tabId: response
        }).then(function(tabInfo) {
            console.log(“The recordId for this tab is: “ + tabInfo.recordId);
        });
    }).catch(function(error) {
            console.log(error);
    });
}
})

Best Answer

With Summer 18 Release, you can open custom lightning components in a new tab.

If You are trying to open MyComponent.cmp in a new tab/subtab, implement this interface lightning:isUrlAddressable in that component.

<aura:component description="MyComponent" implements="lightning:isUrlAddressable">

In the other Component, in which you are trying to fire the tab opening event.

openTab : function(component, event, helper) {
    var workspaceAPI = component.find("workspace");
        workspaceAPI.openTab({
            pageReference: {
                "type": "standard__component",
                "attributes": {
                    "componentName": "c__MyComponent"  // c__<comp Name>
                },
                "state": {
                    "uid": "1",
                    "c__name": component.get("v.myName") // c__<comp attribute Name>
                }
            },
            focus: true
        }).then((response) => {
               workspaceAPI.setTabLabel({
                  tabId: response,
                  label: "App Name / Tab name"
               });
        }).catch(function(error) {
            console.log(error);
        });
}
Related Topic