Newer Version Available

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

openTab() for Lightning Experience

Opens a new workspace tab that displays the content of a specified URL, which can be relative or absolute. If the tab is already open, it is focused. This method works only in Lightning console apps.

Arguments

Name Type Description
recordId ID Specifies the record to open. If you specify a record ID, the value for url isn’t required and is ignored.
url URL

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 tab has focus. To display the tab immediately, set focus to true. To open the tab in the background, set focus to false.
overrideNavRules boolean Optional. Specifies whether the open tab respects existing navigation rules. This argument has no effect on records that have no navigation rules configured and URLs that do not point to a record.

Sample Code

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

Component code:

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

Controller code (recordId):

1({
2    openTab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            recordId: '001xx000003DIkeAAG',
6            focus: true
7        }).then(function(response) {
8            workspaceAPI.getTabInfo({
9                  tabId: response
10            }).then(function(tabInfo) {
11	            console.log(The url for this tab is: ” + tabInfo.url);
12            });
13        })
14        .catch(function(error) {
15               console.log(error);
16        });
17    }
18})

Controller code (url):

1({
2    openTab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            url: '#/sObject/500R0000000myfGIAQ/view',
6            focus: true
7        }).then(function(response) {
8            workspaceAPI.getTabInfo({
9                tabId: response
10            }).then(function(tabInfo) {
11	            console.log(The recordId for this tab is: ” + tabInfo.recordId);
12            });
13        }).catch(function(error) {
14                console.log(error);
15        });
16    }
17})

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 returns a promise that, upon success, resolves to the tabId of the new tab.