I have a lighting web component datatable that is populated from and @wire
call.
Below are the key snippets from my code
import { LightningElement, api, wire, track } from 'lwc';
import getOrderlines from '@salesforce/apex/PP_OrderController.getOrderlines';
import { refreshApex } from '@salesforce/apex';
..
export default class Orderlines extends LightningElement {
@api orderId;
@track wiredDataResult;
...
@wire(getOrderlines, {orderId: '$orderId'}) processOrderline({data, error}) {
this.wiredDataResult = data;
this.orderlines = this.wiredDataResult.listOliWrapper;
...
This is used to populate a datatable:
<lightning-datatable
key-field="orderLineId"
data={orderlines}
columns={columns}
onsave={handleSave}
draft-values={draftValues}
hide-checkbox-column>
</lightning-datatable>
This is all working fine.
In the handleSave()
after sending the update to apex controller (which saves fine), I'm trying to refresh the page using refreshApex
refreshApex(this.wiredDataResult).then(() => {
//Clear all draft values in the datatable
this.draftValues = [];
});
However, I'm getting error from above line as the promise is not being handled. Error:
TypeError: Cannot read properties of undefined (reading ‘then’)“.
I've tried rewriting the @wire to :
@wire(getOrderlines, {
orderId: ‘$orderId’
}) processOrderline( result) {
console.log(‘result’ + JSON.stringify(result));
console.log(‘result.data ’ + JSON.stringify(result.data));
this.wireResult = result;
this.wiredDataResult = result.data;
this.orderlines = this.wiredDataResult.listOliWrapper;
so that I can call the refresh apex on wireResult
(rather than the data part only):
refreshApex(this.wireResult).then(() => {
//Clear all draft values in the datatable
this.draftValues = [];
});
However with this approach the @wire
is not populating the result object.
In the console.log message in the promise I'm getting:
result{}
result.data undefined
and thus the table is not showing on screen.
Any ideas or how to fix this?