openSubtab() for Lightning Experience in Salesforce

openSubtab() for Lightning Experience in Salesforce

Sample Code:

Aura Component:

<aura:component implements=”flexipage:availableForAllPageTypes” access=”global” >
   
    <lightning:workspaceAPI aura:id=”workspace” />
    <lightning:button label=”Open Tab with Subtab” onclick=”{! c.openTabWithSubtab }” />
   
 </aura:component>

 
JavaScript Controller:

({
   
    openTabWithSubtab : function(component, event, helper) {
       
        var workspaceAPI = component.find(“workspace”);
        workspaceAPI.openTab({
            recordId: ‘0015w0000298JM7AAM’,
            focus: true
        }).then(function(response) {
            workspaceAPI.openSubtab({
                parentTabId: response,
                recordId: ‘0035w000034EYn1AAG’,
                focus: true
            });
        })
        .catch(function(error) {
            console.log( ‘Error is ‘ + error );
        });
       
    }
   
})

Output:

Leave a Reply