I am using refreshApex to get the latest data with a button. There is a possibility that there are no new changes and I want to display a message indicating there are no new changes.


  1. How can I detect if there are changes or no changes when using the refreshApex method?

What I tried so far but no luck


import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';

export default class Record extends LightningElement {
    @api recorded;

    @wire(getRecord, { recordId: '$recordId', fields: ['Account.Name'] })
    wiredActivity(value) {
        this.wiredRecord = value;
        const {data, error} = value;
        if(data) { ... }
        else if (error) { ... }

    handleClick() {
       // I can't figure out how to check if different ---- help here


   <button onclick={handleClick}>My button</button>

1 Answer 1


refreshApex is asynchronous, so you can copy the old value and compare to the new after waiting for new results:

async handleClick() {
  let oldData = JSON.stringify(this.wiredRecord.data);
  await refreshApex(this.wiredRecord);
  let newData = JSON.stringify(this.wiredRecord.data);
  if(oldData === newData) {
    // Nothing has changed //

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .