focusTab() for Lightning Experience

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

The method provides the same argument for both Aura Components and Lightning Web Components (LWC).

NameTypeDescription
tabIdstringID of the workspace tab or subtab on which to focus.

This component has a function that retrieves information of all tabs using getAllTabInfo(), which returns an array of tabInfo objects. Then, it uses focusTab(allTabs[0].tabId) to focus on the first tab in the array.

For another example that uses focusTab(), see the workspaceAPIFocusTab component in the lwc-recipes repo.

To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.

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

Component code:

Controller code:

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.

This method returns a promise that, upon success, resolves to true.