0

I have a lwc component that used apex controller on account page when the account updated, my component is not refreshing with latest data updated on account. Is there any listener available in lwc?

handleUpdate() something like?

Code:

import { LightningElement, api, wire, track } from "lwc";
import { refreshApex } from '@salesforce/apex';
import getAccount from "@salesforce/apex/AccountHealthCheckController.getAccount";
refreshApex(this.account); //ERROR
refreshApex(getAccount); //ERROR
export default class AccountHealthChecklwc extends LightningElement {
 @api recordId;
  @track account;
  @track error;
@wire(getAccount, { accountId: "$recordId" })
  wiredGetAccount({ error, data }) {
    if (data) {
      this.error = undefined;
      this.validationMessages( data );
      console.log(this.summary);
    } else if (error) {
      this.error = error;
      this.account = undefined;
    }
  }

 validationMessages( value ) {
  this.account = value;

  //LOGIC
}
}

enter image description here

6
  • To clarify, you've a LWC named Health Check which displays data from an account record which is displayed in its standard detail page. And that you want to refresh the Health Check LWC whenever there's a change on the account record, is that right? If that's the case, then please edit your question to reflect this ask appropriately and also take a look at how to ask to get help. We will also need to see the code you have in Health Check. I would think you need to use LDS here.
    – Jayant Das
    Mar 13, 2019 at 17:44
  • @JayantDas updated code Mar 13, 2019 at 18:21
  • What you are asking is not possible as of today as far as I can say. Take a look at this answer where in future having LDS will work and it will refresh the details based on any record change. In the meantime, you will need to imperatively call your apex method as linked in the comment above by Pranay.
    – Jayant Das
    Mar 13, 2019 at 20:01
  • As @JayantDas mentioned you should use imperative Apex. Basically your use case - refresh on every change - doesn't map to what '@wire' is defined for. Also: is your Apex method getting data from a single record? In that case I HIGHLY recommend that you move to using '@wire(getRecord)' (see developer.salesforce.com/docs/component-library/documentation/…), because that will be give you a lot of additional benefits once Live Record is out. Mar 14, 2019 at 3:51
  • @muenzpraeger Let me rephrase my question I have a lwc component that used apex controller on account page when the account updated my component is not refreshing. Is there any listener available in lwc? The class is large I can't re-do it in JS Mar 14, 2019 at 16:36

0

Browse other questions tagged .