Lightning web Component updateRecord Example

Let us discuss here how to use lightning/uiRecordApi module adapters. This module includes wire adapters to record data and get default values to create records. It also includes JavaScript APIs to create, delete, update, and refresh records. one of the most of importance function is updateRecord that will be used to update the record in the database without using apex class.


the updateRecord syntax looks like below

  • recordInput— (Required) A RecordInput object used to update the record. To create the object, call generateRecordInputForUpdate(record).
  • clientOptions— (Optional) To check for conflicts before you update a record, pass const clientOptions = {'ifUnmodifiedSince' : lastModifiedDate}. Get lastModifiedDate via a wire service adapter that returns a record object: const lastModifiedDate = record.fields.LastModifiedDate.value;.
  • A Promise object that resolves with the updated record. The record contains data for the fields in the record layout.

Create a Lightning Web component

create a new lightning web component using this SFDX command

use this updaterecord.html code

Use this updaterecord .js code

use this updaterecord.js-meta.xml


Push changes to scratch org.

Push changes to scratch using this command and add this component to record page using lighting app builder


Understand  the code

The following JavaScript code will update the tracked properties when an input value is changed

The following code will call from the update button  which contains the record details for the update using the updateRecord function