I've a Lightning Data table and I'm using Promise.all(promises) as mentioned in the documentation from updating multiple record changes in the inline editing. https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_table_inline_edit
I've a validation rule that throws error when I try to update the record with negative value in one of the field which is used in Inline Editing as a column. The problem is that I've getting the uncaught(in promise) and I can se the validation rule error message as well on the developer console but that contains the message thrown from validation rule.
Error - {status: 400, body: {…}, headers: {…}} body: enhancedErrorType: "RecordError" message: "An error occurred while trying to update the record. Please try again." output: {errors: Array(1), fieldErrors: {…}} statusCode: 400 [[Prototype]]: Object headers: {} status: 400 ok: (...) statusText: (...) [[Prototype]]: Object.
Code-
handleSave(event) {
//save last saved copy
this.lastSavedData = JSON.parse(JSON.stringify(this.tableData));
//this.tableData = this.lastSavedData;
console.log('this.tableData', JSON.stringify(this.tableData));
const recordInputs = this.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((rec) => {
console.log('::inside then'+ rec);
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Records updated',
variant: 'success'
})
);
//Clear all draft values
this.draftValues = [];
refreshApex(this.data);
console.log('Refreshed Data', JSON.stringify(refreshApex(this.data)));
//location.reload();
//return refreshApex(this.data);
return refreshApex(this.data);
// Display fresh data in the datatable
}).catch(error => {
console.log('error',JSON.stringify(error));
this.dispatchEvent(
new ShowToastEvent({
title: "Error on update",
message: error.body.output.errors[0].errorCode + '- '+ error.body.output.errors[0].message,
variant: "error"
})
);
});
}
Expectation is to display message using the error object in the catch block but the execution does not covers the catch block even after the uncaught exception.
Any suggestions might be helpful.