LWC way
<lightning-record-edit-form
object-api-name={objectApiName}
record-id={recordId}
>
<lightning-input-field field-name={nameField}> </lightning-input-field>
<div class="slds-var-m-top_medium">
<lightning-button variant="brand" type="submit" label="Save">
</lightning-button>
</div>
</lightning-record-edit-form>
AURA Way
<aura:component>
<lightning:recordEditForm recordId="003XXXXXXXXXXXXXXX" objectApiName="Contact">
<lightning:messages />
<lightning:outputField fieldName="AccountId" />
<lightning:inputField fieldName="FirstName" />
<lightning:inputField fieldName="LastName" />
<lightning:inputField fieldName="Email" />
<lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" />
</lightning:recordEditForm>
</aura:component>
use record edit form component to create a form that’s used to add a Salesforce record or update fields in an existing record on an object. The component displays fields with their labels and the current values and enables you to edit their values.
lightning record edit form
supports the following features.
- Editing a record’s specified fields, given the record ID.
- Creating a record using specified fields.
- Customizing the form layout
- Custom rendering of record data
lightning record edit form
implements Lightning Data Service and doesn’t require additional Apex controllers to create or update record data. This component also takes care of field-level security and sharing for you, so users see only the data they have access to.
Common Errors – why fields are not loaded in record edit form
- User does not have access to those fields
- Object name in the attribute object-api-name={objectApiName} or ObjectApiName=”Account” is not valid
- Onload error