HTML
<template>
<lightning-card title="Create Contact">
<lightning-layout>
<lightning-layout-item size="6" padding="around-small">
<lightning-card>
<lightning-input name="Name " label="Name" onchange={nameHandler}></lightning-input>
<lightning-input name="Email " label="Email" onchange={emailHandler}></lightning-input>
<br>
<lightning-button label="Create Contact " onclick={createContact} ></lightning-button>
</lightning-card>
<div style="color:green"><b>{message}</b></div>
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
JavaScript
import { LightningElement,track } from 'lwc';
import {createRecord} from "lightning/uiRecordApi";
export default class CreateContactLDS extends LightningElement {
@track Name;
@track Email;
message;
nameHandler(event)
{
this.Name=event.target.value;
}
emailHandler(event)
{
this.Email=event.target.value;
}
createContact()
{
const fields={'LastName':this.Name,'Email':this.Email};
const recordInput={apiName:'Contact',fields};
createRecord(recordInput).then(response=>{
this.message='Contact has been created successfully.';
}).catch(error=>{
this.message=('An error occured while creating a contact.');
});
}
}