Actually, there is a Push Notifications feature in the Service Cloud Console that I was unaware of, there is even a Trailhead that covers this.
In order to enable it:
Go to User Name | Setup | Create (Under App Setup) | Apps
Click edit next to the "Support Console" application
Scroll to "Choose how Lists Refresh" and select "Refresh List"
Click the "Select objects and fields for notifications" link next to
"Choose Push Notifications"
On the Push Notification page, Click the Edit Button.
Select the "Cases" object in the available items and click the Add
button to move it to the Selected items.
Next to the "Chose fields for push notifications" the Cases object
should now be shown. Click the Edit link next to it to select the
fields that will trigger a refresh.
On the "Select Cases List fields" Selects the fields you want to trigger a refresh
I created.
Save
The documentation can be found here
We had a similar cache issue in the past and managed to resolve it using @wire(CurrentPageReference)
and getter/setter methods instead of connectedCallback
.
[as @nbrown pointed out in the comments]
Reference docs :
The connectedCallback() hook is invoked with the initial properties passed to the component. If a component derives its internal state from the properties, it's better to write the logic in a setter than in connectedCallback()
@wire(CurrentPageReference)
captures the updated parameter state each time the page is loaded, then you can invoke your custom logic based on the new state parameter value.
Here's some sample code to get you started using CurrentPageReference
LWC componnent tab
HTML
<template>
<div class="slds-grid slds-theme_default slds-box">
<div class="slds-col slds-size_4-of-12">
<h2 class="slds-text-heading_small slds-var-m-bottom_medium">
Load Id : <code> {loadId}</code>
</h2>
</div>
<div class="slds-col slds-size_8-of-12" if:true={objectApiName}>
<lightning-record-view-form
object-api-name={objectApiName}
record-id={loadId}>
<div class="slds-box">
<lightning-output-field field-name="Name"> </lightning-output-field>
</div>
</lightning-record-view-form>
</div>
</div>
</template>
JS
import { LightningElement,api, wire, track } from 'lwc';
import { CurrentPageReference, NavigationMixin } from 'lightning/navigation';
export default class LwcCustomTab extends NavigationMixin(LightningElement) {
currentPageReference;
@api loadId;
@api objectApiName;
@wire(CurrentPageReference)
getCurrentPageReference(currentPageReference) {
this.currentPageReference = currentPageReference;
//show spinner if processing is long
new Promise(
(resolve, reject) => {
setTimeout(() => {
if(this.currentPageReference){
this.loadId = this.currentPageReference.state.c__loadId
? this.currentPageReference.state.c__loadId : null;
this.objectApiName = this.currentPageReference.state.c__objectApiName
? this.currentPageReference.state.c__objectApiName : null;
//perform additional logic with new loadId
resolve();
}
}, 0);
})
.catch((error) => {
console.error(JSON.stringify(error));
})
.finally(() => {
// disable a spinner if applicable
});
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>
LWC redirecting to custom tab
HTML
<template>
<div class="slds-grid slds-theme_default slds-box">
<div class="slds-col"></div>
<div class="slds-col">
<lightning-button label="Redirect To Tab" variant="brand"
onclick={navigateToCustomTab} ></lightning-button>
</div>
</div>
</template>
JS
import { LightningElement, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class LwcNavigateToTab extends NavigationMixin(LightningElement) {
@api loadId;
@api recordId;
@api objectApiName;
navigateToCustomTab(){
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: {
apiName: 'LWC_Custom_Tab'
},
state: {
c__loadId : this.recordId ? this.recordId : this.loadId,
c__objectApiName : this.objectApiName
}
});
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage,lightning__AppPage,lightning__HomePage">
<property name="loadId" label="Custom Load Id" type="String" />
<property name="objectApiName" label="Object API Name" type="String" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Best Answer
Editing this answer as per discussion in the comments section.
It is not directly possible to refresh LWC tab. It can be achieved by wrapping LWC inside aura component as below :
1 Create a aura component which renders the desired LWC using
<aura:if>
and use it as the tab.2 For detecting navigation away from the tab , handle
aura:locationChange
event as below :here ,
handleLocationChange
will just toggle the property inaura:if
which will cause the LWC to rerender.Special credits to @mackmama for this.