I'm trying to use multiple inline edits to update values of the datatable, I've looked at the previous answers and created this accountEditList property to refresh apex. It doesn't seem to work.
import {LightningElement, api, track, wire} from 'lwc';
import getAccountEditList from '@salesforce/apex/AcccountEditController.getAccountEditList';
import {updateRecord} from 'lightning/uiRecordApi';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import {refreshApex} from '@salesforce/apex';
export default class Acceditdatatable extends LightningElement {
@api accountIdList = [];
@api saveDraftValues = [];
@api accountEditList = [];
@track draftValues = [];
@track updateRows = [];
@track columns = [
{label: 'Name', fieldName: 'Name', type: 'text', editable: true},
{label: 'Website', fieldName: 'Name', type: 'text', editable: true},
{label: 'Date', fieldName: 'Acc_Custom_Date__c', type: 'date', editable: true},
{label: 'Email', fieldName: 'Acc_Custom_Email__c', type: 'email', editable: true},
];
@wire(getAccountEditList, {Ids: '$accountIdList'})
wiredAccount(data, error) {
this.updateRows = data;
if (data) {
this.accountEditList = data;
console.log('totalaccountsaftersearchwireservice', this.accountEditList);
}
}
handleSave(event) {
const recordInputs = event.detail.draftValues.slice().map(draft => {
const fields = Object.assign({}, draft);
return {fields};
});
console.log('RECORDINPUTS', recordInputs);
const promises = recordInputs.map(recordInput => updateRecord(recordInput));
Promise.all(promises).then(() => {
// Clear all draft values
this.draftValues = [];
// Display fresh data in the datatable
return refreshApex(this.updateRows);
}).catch(error => {
// Handle error
});
}
Console statement : RECORDINPUTS [{"fields":{"Name":"test1","id":"row-0"}},{"fields":{"Name":"test2","id":"row-1"}}]
Best Answer
Your console statement shows that you are not setting your id field correctly. If you're using lightning-datatable, you need to specify the key field correctly to grab the id values from the edit event.