Newer Version Available

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

focusTab() for Lightning Experience

Focuses a workspace tab or subtab. This method works only in Lightning console apps.

Arguments

Name Type Description
tabId string ID of the workspace tab or subtab on which to focus.

Sample Code

This component has a button that, when pressed, opens a new tab and focuses it.

Component code:

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

Controller code:

1({
2    focusNewTab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            url: '/lightning/r/Account/001xx000003DI05AAG/view',
6        }).then(function(response) {
7            workspaceAPI.focusTab({tabId : response});
8       })
9        .catch(function(error) {
10            console.log(error);
11        });
12    }
13})

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 true.