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 specified tab is already open, it is focused.

Arguments

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

Sample Code

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

Component code:

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

Controller code:

1({
2	openTab : function(component, event, helper) {
3        var workspace = component.find("workspace"); 
4        workspace.openTab({
5            url: '/sObject/001R0000003HgssIAC/view', 
6            focus: true,  
7            callback : function(error, response) { 
8                workspace.focusTab({tabId : response});  
9            }
10        });
11    },
12})

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 workspace tab.