Newer Version Available

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

refreshTab() for Lightning Experience

Refreshes a workspace tab or a subtab specified by tabId. Keep in mind that the first subtab has the same tabId as the workspace tab. This method works only in Lightning console apps.
If this method is invoked for a workspace tab with unsaved changes, a confirmation window opens for the user.
  • 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.

1import { LightningElement, wire } from 'lwc';
2import { IsConsoleNavigation, getFocusedTabInfo, refreshTab } from 'lightning/platformWorkspaceApi';
3
4export class RefreshTabExample extends LightningElement {
5    @wire(IsConsoleNavigation) isConsoleNavigation;
6
7    handleClick() {
8        if (this.isConsoleNavigation) {
9            getFocusedTabInfo().then((tabInfo) => {
10                refreshTab(tabInfo.tabId);
11            }).catch((error) => {
12                console.log(error);
13            });
14        }
15    }
16}

Example

The lwc-recipes repo has a workspaceAPIRefreshTab component that demonstrates usage of the refreshTab() method.

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})

Response

This method returns a promise that, upon success, resolves to true. If there was an error, the promise is rejected.

true doesn’t necessarily mean that the refresh was successful. For example, if the tab has unsaved changes when this method was called, the user has a choice to save or discard their changes. The refresh is canceled depending on user’s choice.

Note