Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
lightning__tabUpdated
Response
The response is the same as that of the lightning:tabUpdated Aura app event.
LWC Example
Import the lightning__tabUpdated message channel from the @salesforce/messageChannel/ scoped module. The event returns the message in the response.
1import { LightningElement, track, wire } from "lwc";
2import { MessageContext, subscribe, unsubscribe, APPLICATION_SCOPE } from "lightning/messageService";
3import tabUpdatedChannel from "@salesforce/messageChannel/lightning__tabUpdated";
4
5export default class TabUpdatedExample extends LightningElement {
6 subscription = null;
7 @wire(MessageContext) messageContext;
8
9 // Encapsulate logic for Lightning message service subscribe and unsubscribe
10 subscribeToMessageChannel() {
11 if (!this.subscription) {
12 this.subscription = subscribe(
13 this.messageContext,
14 tabUpdatedChannel,
15 (message) => this.handleMessage(message),
16 { scope: APPLICATION_SCOPE }
17 );
18 }
19 }
20
21 unsubscribeToMessageChannel() {
22 unsubscribe(this.subscription);
23 this.subscription = null;
24 }
25
26 // Handler for message received by component
27 handleMessage(message) {
28 // do something
29 }
30 // Standard lifecycle hooks used to subscribe and unsubscribe to the message channel
31 connectedCallback() {
32 this.subscribeToMessageChannel();
33 }
34
35 disconnectedCallback() {
36 this.unsubscribeToMessageChannel();
37 }For more information, see Subscribe and Unsubscribe from a Message Channel.