HTML
<template>
<lightning-card>
<lightning-button label="Publish Event" onclick={handleClick}></lightning-button>
</lightning-card>
<div style="color:green; font-size:14px; font-weight:bold; text-align:center">{message}</div>
</template>
JavaScript
import { LightningElement } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';
export default class PublishEvent extends LightningElement {
message;
handleClick() {
const fields = { 'Name': 'Bank of America' };
const recordInput = { apiName: 'Account', fields };
createRecord(recordInput)
.then(response => {
this.message = 'Record has been created successfully.';
})
.catch(error => {
this.message = `An error occurred while creating the record: ${error.body.message}`;
});
}
}