0

After editing the handleSubmit actually saves the data as shown:

handleSubmit(){
        var dataList = {};
        //newData is records the updated data.
        updateMapFieldData({mapFieldData : this.newData});
        this.closeEditModal();
        return refreshApex(this.data);
    }

data is sent to the lightning-datatable inorder to display the data.

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

data;
error;
@wire(getAllData, {recordId:'$recordid'})
    wiredData({error, data}) {
        if (data) {
            this.data = data;
        } else if(error) {
            this.error = error;
        }
    }

As you can see I tried refreshApex but it didnt work, and I dont know what is the mistake here.

1

Refresh apex does not work on just the data but the whole result of wired apex. So you need to make some changes to your code.

wiredDataRes; 
@wire(getAllData, {recordId:'$recordid'})
wiredData(result) {
    this.wiredDataRes = result;
    let {error, data} = result;
    if (data) {
        this.data = data;
    } else if(error) {
        this.error = error;
    }
}

Now use the result with refresh apex.

refreshApex(this.wiredDataRes);
5
  • it is working, but the refresh is happening, for the 2nd edit. For example: If I am editing two times, then after the 2nd time the value of the 1st edit is visible. – sfdcLearner May 14 '20 at 12:50
  • @yashshah It will get called every time handleSubmit is called. Please check if its getting called correctly. – Rahul Gawale May 14 '20 at 12:52
  • 1
    yes it worked this time, with minor changes at the handleSubmit – sfdcLearner May 14 '20 at 13:45
  • @yashshah was the name of the property the problem? – Rahul Gawale May 14 '20 at 13:55
  • 1
    Yes the function name and the property name cannot be same. It threw an error for me. @rahulgawale – sfdcLearner May 15 '20 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.