Notes:
1. Cancel & Save buttons are implicitly added on the form.
2. lighting-record-form is a Lightning Data Service component. It takes care of the below capabilities:
a. Field level security
b. Record visibility based on User sharing access.
<template> <lightning-card> <lightning-record-form object-api-name={objname} fields={flds} onsuccess={handleSuccess}></lightning-record-form> </lightning-card> </template>
import {LightningElement} from 'lwc'; import {ShowToastEvent} from 'lightning/platformShowToastEvent'; import accObj from '@salesforce/schema/Account'; import accname from '@salesforce/schema/Account.Name'; export default class RecordFormExample extends LightningElement { objname = accObj; flds = [accname]; handleSuccess(event) { const toastEvent = new ShowToastEvent({ title: "Account created", message: "Record ID: " + event.detail.id, variant: "success" }); this.dispatchEvent(toastEvent); } }
<?xml version="1.0" encoding="UTF-8" ?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>50.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__RecordPage</target> <target>lightning__HomePage</target> </targets> </LightningComponentBundle>
Comments
Post a Comment