3

I have a button which is a quick action and I am calling a LWC and the logic is handled in the invoke method. Below is the LWC structure.

@wire(getRecord)
.
.
@wire(getRelatedListRecords)
.
.
@api invoke(){
..
}

I want to call @wire(getRelatedListRecords) in the invoke method or I want to reload the LWC component on clicking the button. Is this possible?

1
  • @wire methods are invoked by lwc engine every time the respective property is updated. To control such behavior use Imperative Apex instead. Commented May 7, 2022 at 13:47

2 Answers 2

3

Data fetched from Wire Callouts are stored in browser cache. If you want to refresh the cached data please use refreshApex().

import { refreshApex } from '@salesforce/apex';

@wire(getRecord) 
theRecord;

wiredValues;
@wire(getValues)
theValues(value) {
    this.wiredValues = value;
}

handlerMethod(){
 refreshApex(this.theRecord)
 refreshApex(this.wiredValues)
}

Please go through the documentation.

1

Wire methods are called automatically and cannot be called directly. Simply accessing the data in the invoke method should already have the data you want to access.

5
  • 1
    The wire method is currently holding the old value. I want to access the wire method again to fetch the latest value. Is there any other way to access it?
    – Raksha
    Commented May 7, 2022 at 6:28
  • 2
    @Raksha In that case, use refreshApex, as noted in the other answer.
    – sfdcfox
    Commented May 7, 2022 at 12:48
  • what if you want to access the data from a different lwc? ie you have a service lwc to get some records, and then a UI lwc that calls it and displays the result as a table?
    – Aequitas
    Commented May 31, 2023 at 5:52
  • @Aequitas Do you mean "service component" as in "a component with no HTML template"? Last time I tried, wire didn't seem to be supported in this context, as there are no lifecycle events, so wire simply doesn't work. Otherwise, if it has a template, you can include it in the parent component, and it can let the parent know new data is available through an event. This data must be exposed by an api property, though. If this is unclear, I suggest you ask a new question, I'll be happy to answer in more detail.
    – sfdcfox
    Commented May 31, 2023 at 6:11
  • yeah that's right, thank you, that's what I figured from my testing, but, oh well I guess, thanks.
    – Aequitas
    Commented Jun 6, 2023 at 23:12

You must log in to answer this question.

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