I have a Case page layout with a Record Detail component which allows me to edit the record, upon saving I want to refresh my custom LWC in the same page.
I know I can use refreshApex wired to a method to refresh the component data, I was able to trigger this with a button, but I wanted it to be automatic handling a record update event.
import { LightningElement, api, wire, track } from 'lwc';
import getHistory from '@salesforce/apex/ComponentController.getHistoryRecords';
export default class HistoryLWC extends NavigationMixin(LightningElement) {
@api recordId;
@api isLoaded = false;
@track historyList;
@track error;
wiredActivities;
@wire(getHistory, { currentRecordId: '$recordId' })
wiredHistory( result ) {
this.wiredActivities = result;
if (result.data) {
this.historyList = result.data;
this.isLoaded = true;
}
else if (result.error) {
this.error = result.error;
this.isLoaded = true;
}
}
refreshTimeline(evt) {
return refreshApex(this.wiredActivities)
.then(() => {
this.isLoaded = true;
});
}
}
This is the method which I'm calling from a ui button to refresh the page.
Context: I have a big object which is used as history for case records, when updating a case record a new big object record is created. In the case record page I have my LWC which will display the history records, when saving a case record I want my component to call the controller to query the history records again. I'm thinkin of an event to be handled on my lwc or a method which will run everytime the record page is updated, I saw that getRecord for example will run everytime a component loads.