Newer Version Available

This content describes an older version of this product. View Latest

openSubtab() for Lightning Experience

Opens a subtab within a workspace tab. The new subtab displays the content of the specified URL. If a tab with that URL already exists and focus is set to true, it is focused.

Arguments

Name Type Description
parentTabId string The ID of the workspace tab within which the new subtab should open.
url string The URL representing the content of the new subtab. URLs can be either relative or absolute.
focus boolean Specifies whether the new subtab has focus.
callback function JavaScript method called upon completion of the method. Returns the tabId of the subtab.

Sample Code

This component has a button that, when pressed, opens a tab with a subtab.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <force:workspaceAPIAccess aura:id="workspace" />
3    <lightning:button label="Open Tab with Subtab" onclick="{! c.openTabwithSubtab }" />
4</aura:component>

Controller code:

1({    
2    openTabWithSubtab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            url: '#/sObject/001R0000003HgssIAC/view', 
6            focus: true,
7            callback : function(error, response) { 
8                workspaceAPI.openSubtab({
9                    parentTabId : response, 
10                    url : '#/sObject/005R0000000INjPIAW/view', 
11                    focus: true 
12                });  
13            }
14        });
15    }
16})

The relative URL used in this example is a placeholder. To try this example yourself, use a relative URL with a record ID from your org.

Note

Response

This method is asynchronous, so it returns its response in a callback method, in an object that contains the following field.
Name Type Description
id string The tabId of the new subtab.