I have a save and a cancel, both triggered by a button click:
saveCriteria(){
let criteriaToSave = [];
//reassemble drill up/down fields on the criteria
for(let i = 0; i < this.tableData.length; i++){
criteriaToSave.push(parseObjectFieldsForDrillDown(this.tableData[i]));
}
//pass tableData to apex to save.
saveCriteriaUpdates({criteriaJSON: JSON.stringify(criteriaToSave), criteriaApiName: this.objectName})
.then(result => {
console.log(result);
return refreshApex(this.wiredResults);
//Show toast on success/error
}).catch(error => {
console.log(JSON.stringify(error));
//Show toast on error
});
}
cancelUpdates(){
return refreshApex(this.wiredResults);
}
The refreshApex() works in the then callback of the apex method call on save. I see my debugs from my wire function after saving again.
But when I just click cancel, I want to refresh my data to its original state from the server to wipe out all changes, so want to do a refreshApex(). But in the cancel, the refreshApex does nothing. I don't see my debugs from my wire function. No debugs from the error part of the wire function... my table does not refresh back to its original state... nothing.
Is there some trick to refreshApex I am missing? It seems to work in an asynchronous callback, but not a direct call like my cancel button...
PS: My wire function and extra property for refresh looks like this:
wiredResults;
@wire(getSObjectsForTable, {stepId: '$stepId', objectApiName: '$objectName'})
getSObjectsForTable(result){
this.wiredResults = result;
if(result.data){
console.log(result.data);
this.tableData = getTableData(result.data);
this.tableColumns = getColumns(this.tableData, allColumns);
} else if(result.error){
console.log(result.error);
let toastEvent = new ShowToastEvent({
title: 'Error',
message: 'Error retrieving records: ' + result.error,
variant: 'error'
});
this.dispatchEvent(toastEvent);
}
this.tableLoaded = true;
}
return
.