LDS(Lightning Data Service) updateRecord レコードの更新方法

1.updateRecordをインポートします。
import { updateRecord } from 'lightning/uiRecordApi’;
updateRecordはプロミスを返却します。

2.複数件を処理する場合は繰り返し実行する必要があります。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
handleSave(event) {
const fields = {};
fields['Id'] = event.detail.draftValues[0].Id;
fields['FirstName'] = event.detail.draftValues[0].FirstName;
fields['LastName'] = event.detail.draftValues[0].LastName;
const recordInput = {fields};
updateRecord(recordInput).then(() => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Contact updated',
variant: 'success'
})
);
}).catch(error => {
// エラーコード処理
});
}
handleSave(event) { const fields = {}; fields['Id'] = event.detail.draftValues[0].Id; fields['FirstName'] = event.detail.draftValues[0].FirstName; fields['LastName'] = event.detail.draftValues[0].LastName; const recordInput = {fields}; updateRecord(recordInput).then(() => { this.dispatchEvent( new ShowToastEvent({ title: 'Success', message: 'Contact updated', variant: 'success' }) ); }).catch(error => { // エラーコード処理 }); }
handleSave(event) {
     const fields = {};
     fields['Id'] = event.detail.draftValues[0].Id;
     fields['FirstName'] = event.detail.draftValues[0].FirstName;
     fields['LastName'] = event.detail.draftValues[0].LastName;

     const recordInput = {fields};

     updateRecord(recordInput).then(() => {
         this.dispatchEvent(
             new ShowToastEvent({
                 title: 'Success',
                 message: 'Contact updated',
                 variant: 'success'
             })
         );
     }).catch(error => {
         // エラーコード処理
     });
 }

 

IT

Posted by arkgame