lwc datatable при обновлении записи

Следуйте этому руководству по работе с lwc datatable: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_table_inline_edit

При нажатии кнопки "Сохранить" после редактирования значений в столбцах я получаю сообщение об ошибке от Salesforce.

import { LightningElement, wire, track } from "lwc";
import { updateRecord } from "lightning/uiRecordApi";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import { refreshApex } from "@salesforce/apex";
import getAccounts from "@salesforce/apex/AccountController.getAccounts";

const columns = [
  { label: "Name", fieldName: "Name", type: "text", editable: true },
  {
    label: "Annual Revenue",
    fieldName: "AnnualRevenue",
    type: "currency",
    editable: true
  },
  { label: "Industry", fieldName: "Industry", type: "text" },
  {
    label: "Number Of Employees",
    fieldName: "NumberOfEmployees",
    type: "number",
    editable: true
  }
];

export default class AccountsDataTable extends LightningElement {
  @track columns = columns;
  @track draftValues = [];

  @wire(getAccounts) wiredAccounts;

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

    const promises = recordInputs.map(recordInput => updateRecord(recordInput));
    Promise.all(promises)
      .then(accounts => {
        this.showToast("Success", "Accounts Updated", "success");
        // Clear all draft values
        this.draftValues = [];
        // Display fresh data in the datatable
        return refreshApex(accounts);
      })
      .catch(error => {
        this.showToast("Error", error.body.message, "error");
      });
  }

  showToast(title, message, variant) {
    const evt = new ShowToastEvent({
      title: title,
      message: message,
      variant: variant
    });
    this.dispatchEvent(evt);
  }
}

0 ответов

Другие вопросы по тегам