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 exists and focus is set to true, it is focused. This method works only in Lightning console apps.

Arguments

Name Type Description
parentTabId string The ID of the workspace tab within which the new subtab opens.
recordId ID Specifies the record to open. If you specify a record ID, the value for url isn’t required and is ignored.
url string

The URL representing the content of the new workspace tab.

url is optional. If you specify a record ID, the url value is ignored.

The URL can be either relative or absolute. Make sure to include a leading hashtag “#” when adding a relative URL. To use a third-party domain, add the site as a CSP Trusted Site.

focus boolean Specifies whether the new subtab has focus. To display the subtab immediately, set focus to true. To open the subtab in the background, set focus to false.

Sample Code

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

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <lightning:workspaceAPI 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        }).then(function(response) {
8            workspaceAPI.openSubtab({
9                parentTabId: response,
10                url: '#/sObject/005R0000000INjPIAW/view',
11                focus: true
12            });
13        })
14        .catch(function(error) {
15            console.log(error);
16        });
17    }
18})

The relative URL used in this example is a placeholder. Make sure to include a leading hashtag “#” when adding a relative URL. To try this example yourself, use a relative URL with a record ID from your org.

Note

Response

This method returns a promise that, upon success, resolves to the ID of the new subtab.