how to Use refreshApex in Lightning Web Components (LWC)

For this blog post described about to use the refreshApex in Lightning Web Components Controller file.

Today received the error “Refresh failed because resolved configuration is not available” in Lightning Web Component and here is the work around to use with refreshApex in Lightning Web Components (LWC).

import { refreshApex } from ‘@salesforce/apex’;
refreshApex(wiredProperty)

Here:
wiredProperty is A property or method annotated with @wire.

Here is Simple Example to Use refreshApex in Lightning Web Components (LWC):

import { LightningElement, track, api, wire } from 'lwc';
import getAccountList from '@salesforce/apex/AccountController.getAccount';
import saveAccount from '@salesforce/apex/AccountController.insertAccount';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { refreshApex } from '@salesforce/apex';

export default class PremiumQuoteAlteration extends NavigationMixin(LightningElement) {

wiredAccountResults;

// retrieving the data using wire service
@wire(getAccountList)
accountList(result) {
this.wiredAccountResults = result;
if (result.data) {
this.accountData = result.data;
this.error = undefined;

} else if (result.error) {
this.error = result.error;
this.accountData = undefined;
}
}

//to Save the altered Quote payload
saveAccount() {
saveAccount()
.then(result => {

//console.log('alteration result::'+result.Id);
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Account Saved Successfully {0} ',
variant: 'success',
messageData: [{
url: '/'+result.Id,
label: 'Click Here',
}]
}),
);

return refreshApex(this.wiredAccountResults);
})
.catch(error => {
this.error = error;
//console.log('error::'+JSON.stringify(error));
});
}

}

Written by 

Salesforce MVP | Lightning Champion | 16x Salesforce Certified | Application Architect | 6x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*