Newer Version Available
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. 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 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. |
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})Response
This method returns a promise that, upon success, resolves to the
ID of the new subtab.