Newer Version Available
refreshTab() for Lightning Experience
- Continue editing: Changes are preserved and the tab or workspace isn’t refreshed.
- Discard changes: Changes are discarded and the tab or workspace is refreshed.
- Save: Changes are saved and then the tab or workspace is refreshed.
Arguments
The method provides the same argument for both Aura Components and Lightning Web Components (LWC).
| Name | Type | Description |
|---|---|---|
| tabId | string | ID of the workspace tab or subtab to refresh. |
| includeAllSubtabs | boolean | Optional. If the tabId corresponds to a workspace tab, all subtabs within that workspace are refreshed. The default is true. Keep in mind that the first subtab has the same tabId as the workspace tab. |
LWC Sample Code
This component checks if it’s in a Lightning console app, returns information about the focused tab and refreshes it. When the getFocusedTabInfo() method resolves successfully, it returns the tabInfo object. The const { tabId } syntax destructures the tabInfo object and binds the tabInfo.tabId value on the tabId variable. refreshTab() uses this tabId value to refresh the tab and its subtabs.
1import { LightningElement, wire } from 'lwc';
2import {
3 IsConsoleNavigation,
4 getFocusedTabInfo,
5 refreshTab
6} from 'lightning/platformWorkspaceApi';
7
8export default class WorkspaceAPIRefreshTab extends LightningElement {
9 @wire(IsConsoleNavigation) isConsoleNavigation;
10
11 async refreshTab() {
12 if (!this.isConsoleNavigation) {
13 return;
14 }
15 const { tabId } = await getFocusedTabInfo();
16 await refreshTab(tabId, {
17 includeAllSubtabs: true
18 });
19 }
20}This example is the workspaceAPIRefreshTab component from 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.
Aura Components Sample Code
This component has a button that, when pressed, refreshes the focused workspace tab and all its open subtabs.
Component code:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global">
2 <lightning:workspaceAPI aura:id="workspace"/>
3 <lightning:button label="Refresh Focused Tab" onclick="{!c.refreshFocusedTab}"/>
4</aura:component>Controller code:
1({
2 refreshFocusedTab : function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.getFocusedTabInfo().then(function(response) {
5 var focusedTabId = response.tabId;
6 workspaceAPI.refreshTab({
7 tabId: focusedTabId,
8 includeAllSubtabs: true
9 });
10 })
11 .catch(function(error) {
12 console.log(error);
13 });
14 }
15})