0

I want to display a form (LWC) in a Contact record Page to quickly update some fields. There is a way to achieve this whithout using apex, only Lightning Data Service?

1

Use lightning-record-form component to quickly create forms to add, view, or update a record.

Example HTML

<template>
  <lightning-record-form
          record-id={recordId}
          object-api-name={objectApiName}
          fields={fields}
          columns="2"
          mode="edit"
          onsubmit={handleSubmit}>
  </lightning-record-form>
</template>

JS

import { LightningElement, api } from 'lwc';

import NAME_FIELD from '@salesforce/schema/Account.Name';
import REVENUE_FIELD from '@salesforce/schema/Account.AnnualRevenue';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';

export default class RecordFormEditExample extends LightningElement {
    // The record page provides recordId and objectApiName
    @api recordId;
    @api objectApiName;

    fields = [NAME_FIELD, REVENUE_FIELD, INDUSTRY_FIELD];

    handleSubmit(event){
        event.preventDefault();       // stop the form from submitting
        const fields = event.detail.fields;
        fields.LastName = 'My Custom Last Name'; // modify a field
        this.template.querySelector('lightning-record-form').submit(fields);
     }
}
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.