Using Lightning Data Service (LDS) and User interface API (UI API) we can work on data and metadata of salesforce. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded once, no matter how many components are using it.
Now create a simple lwc component to create an account record using lightning-record-form.createNewAccount.html
[<template>createNewAccount.js
<lightning-card title="Create Account" icon-name="standard:account">
<div class="slds-m-around_medium">
<lightning-record-form
object-api-name={accountObject}
fields={accountFields}
onsuccess={handleAccountCreated}
columns="2">
</lightning-record-form>
</div>
</lightning-card>
</template>]
[import { LightningElement } from 'lwc';You can also find the above code in SWDC WORLD
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; // for toast notification
import ACCOUNT_OBJECT from '@salesforce/schema/Account'; // import object
import AC_NAME from '@salesforce/schema/Account.Name'; // import fields
import AC_WEBSITE from '@salesforce/schema/Account.Website';
import AC_NUMBER from '@salesforce/schema/Account.AccountNumber';
import AC_INDUSTRY from '@salesforce/schema/Account.Industry';
import AC_RATING from '@salesforce/schema/Account.Rating';
import AC_PHONE from '@salesforce/schema/Account.Phone';
import AC_TYPE from '@salesforce/schema/Account.Type';
export default class CreateNewAccount extends LightningElement {
accountObject = ACCOUNT_OBJECT; // object type
accountFields = [AC_NAME, AC_WEBSITE,AC_NUMBER, AC_INDUSTRY, AC_RATING, AC_PHONE, AC_TYPE]; // fields to be showin in form
// shows toast message after account creation
handleAccountCreated(){
// Run code when account is created.
const showSuccess = new ShowToastEvent({
title: 'Success!!',
message: 'Account has been created',
variant: 'Success',
});
this.dispatchEvent(showSuccess);
}
}]
COMMENTS