The Salesforce Developers website will undergo maintenance on May 29, 2024 from 3:00 a.m. UTC to 10:00 a.m. UTC. The maintenance process may affect the availability of our documentation. Please plan accordingly.

updateRecord(recordInput, clientOptions)

Updates a record. Provide the record Id of the record to update in recordInput.

updateRecord uses this User Interface API resource, but doesn’t support all its parameters.

  • recordInput— (Required) A RecordInput object used to update the record. To create the object, call generateRecordInputForUpdate(record, objectInfo). Alternatively, create the RecordInput object by passing in the fields and their values. See the Usage section. The following are recordInput properties:

    • triggerOtherEmail— (Optional) For a case, specifies whether to send email to users outside the organization. In Salesforce, this email can be triggered by creating, editing, or deleting a contact for a case. The default value is false.

    • triggerUserEmail— (Optional) For a case or a lead, specifies whether to send email to users in the organization. In the Salesforce user interface, this email can be triggered by various events: resetting a password, creating a user, changing the case owner, or adding comments to a case. The default value is false.

      For case owner changes, also set useDefaultRule=true, or no email is sent.

    • useDefaultRule—For a case or lead, specifies whether to use the default (active) assignment rule. If you specify useDefaultRule, don’t specify an assignmentRuleId. The default value is false.

      For an Account, specifies whether to apply the default territory assignment rules.

    • allowSaveOnDuplicate—Specifies whether to save a duplicate record. The default value is false.

    • apiName—To create a record, specify the API name of an object from which to create the record. To update a record, use null or don’t pass this property.

    • fields—Map of field names to field values. See Update a 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.

Before you use this wire adapter, make sure that there isn’t an easier way to update the data. To create a form for working with records, consider the lightning-record-*-form components.

Create a custom form only if you need more customization than the lightning-record-*-form components allow.

This example creates a custom form that updates a record. It uses a getSingleRecord Apex controller to load the FirstName and LastName fields for a single contact record. (Name is a compound field. To edit the name, you must use the FirstName and LastName fields.)

As a custom behavior, the Update Contact button is disabled when one or both name fields are empty. The Id field is for reference only and is disabled so users can’t edit it.

Changes are updated using updateRecord. Requiredness is not enforced on the client-side. To display field-level errors on invalid fields, call reportValidity().

If you use the lightning-record-*-form components, all fields are displayed based on your Salesforce schema. For example, it automatically handles requiredness on the client-side for required fields. To customize how the form works, use updateRecord. For example, you can prevent users from leaving the non-required FirstName field blank to improve data completeness, or disable the button when specific fields aren’t valid.

The getSingleContact Apex method returns a single contact record.

See Also