Build Custom UI to Create and Edit Records
lightning-record*form components meet your needs. See Compare Base Components.
This document explains the
ldsCreateRecord component in the lwc-recipes repo. The component asks for a name and creates an account with that name. When the account is created, it renders the account Id.
createRecord() function. This component calls the function in the
createRecord from the
lightning/uiRecordApi module. To display notifications for error handling, it imports
lightning/platformShowToastEvent. It also imports references to the Account object and Account name field.
fields values for your
recordInput object. In the example, we pass in
fields on the
recordInput object using a shorthand syntax, instead of passing in
fields: fields. Then, pass the account name to
createRecord(recordInput), which creates an account record based on the name you provide.
Next, provide a handler that creates an account record using
createRecord(recordInput). In this example, the
handleNameChange(event) method handles a
change event from the component HTML file when a user enters an account name.
createRecord(recordInput) function returns a Promise object that resolves when the record is created. To return record data back to the component, use the
then() block. This component returns the
account.id and sets it to the
Handle errors using the