0

When doing an update on multiple rows with inline editing, I'm always being met with an error. I've utilised the updateRecord(recordInput) from this document to save multiple rows however I keep getting the error shown below. The update to single row from the same document is working in contrast.

enter image description here

The draft values are being recognized as shown in my DevTools:

enter image description here

Related: https://github.com/salesforce/lwc/issues/1537

Is this a known issue? What am I doing wrong and how can I get this to work correctly?

Here are my code:

JS

import { LightningElement, wire, track, api } from 'lwc';
import { updateRecord } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';

@track refreshTable = [];
@track draftValues = [];
@track saveDraftValues = [];

handleSave(event) {

    let draftValues = event.detail.draftValues;

    const recordInputs =  event.detail.draftValues.slice().map(draft => {
        const fields = Object.assign({}, draft);
        return { fields };
    });

    console.log('RECORDINPUTS', JSON.stringify(recordInputs));

    const promises = recordInputs.map(recordInput => updateRecord(recordInput));
    Promise.all(promises).then(() => {

         this.saveDraftValues = [];

         return refreshApex(this.refreshTable);
    }).catch(error => {
        // Handle error
    });

HTML

<template>
    <lightning-card title="Edit Products" icon-name="standard:opportunity">
         <div class="slds-m-around_large" style="height: 400px;">
            <template if:true={oppLines}> 
                    <c-custom-data-table 
                        key-field="id"
                        data={oppLines}
                        columns={columns}
                        onsave={handleSave}
                        draft-values={saveDraftValues}
                        onvalueselect={handleSelection}                         
                        >
                    </c-custom-data-table>
            </template>
            <template if:true={error}>
                <p>{oppLines.error}</p>
            </template>
        </div>
    </lightning-card>
    <div>
        {loadMoreStatus}
    </div>    
</template>
1
  • 1
    So you gotta do some debugging stepping through the code to find which line throws for you.Clearly it is after your RECORDINPUTS console.log. Lastly, at least where i used this, the Id in the fields HAD to be Id not id. (Pascal cased)
    – zaitsman
    Commented May 14, 2020 at 4:04

1 Answer 1

1

I have changed key-field="Id" and it got worked for me.. because JS is case Sensitive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .