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;

    @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.

  • Can you please add the LWC here so we can see the function that needs to refresh you page? – Carlos Naranjo Feb 25 '20 at 0:32

Lightning Data Service and the standard Salesforce UI share an integrated cache, so that if one is updated the others also reflect that change. This means that if our custom component makes a change to the record in question, the standard UI does not continue to display stale date.

Similarly, we can leverage this functionality in the opposite direction to trigger a change within our component.

If Lightning Data Service detects a change to a record or any data or metadata it supports, all components using a relevant @wire receive the new value. Please add code for you LWC here or try to see if you can achieve your custom LWC functionality by using the Lightning Data Service wire adapters (lightning/ui*Api)

  • I added the code I'm using to refresh the component onclick. – Rui Vieira Feb 25 '20 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.