Easily update and query data on Salesforce with refreshApex method!
To start, import the refreshApex function from @salesforce/apex.
This method is called to retrieve updated data from Apex and refresh the cache of a wired property.
Here's an example:
import { refreshApex } from "@salesforce/apex";
refreshApex(valueProvisionedByApexWireService);
Remember to use {valueProvisionedByApexWireService} as either an annotated property or an argument received by the wired function.
Please note that using refreshApex for non-Apex wire adapters is no longer recommended.
Instead, utilize notifyRecordUpdateAvailable(recordIds) to refresh data returned by non-Apex wire adapters.
// Example of refreshing data for a wired property
// after you update data via imperative Apex.
import { refreshApex } from '@salesforce/apex';
import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
import getOpptyOverAmount from '@salesforce/apex/OpptyController.getOpptyOverAmount;
@wire(getOpptyOverAmount, { amount: '$amount' })
opptiesOverAmount;
// Update the record in Apex, such as via a button click
// Refresh Apex data that the wire service provisioned
handler() {
updateRecordApexMethod()
.then(() => {
refreshApex(this.opptiesOverAmount);
notifyRecordUpdateAvailable(recordIds);
// Refresh the Lightning Data Service cache
});
}
Follow Us