HTML
<template>
<div class="slds-m-around_medium">
<lightning-button variant="destructive" label="Delete Account"
title="Delete Account" onclick={deleteRecord}></lightning-button>
</div>
</template>
Java Script
import { LightningElement, api, track } from 'lwc';
import { deleteRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class DeleteAccount extends LightningElement {
@api recordId = '0038b00002in40SAAQ';
@api objectApiName;
deleteRecord() {
deleteRecord(this.recordId)
.then(() => {
const toastEvent = new ShowToastEvent({
title: 'Success',
message: 'Record deleted successfully',
variant: 'success'
});
this.dispatchEvent(toastEvent);
})
.catch(error => {
const toastEvent = new ShowToastEvent({
title: 'Error',
message: error.body.message,
variant: 'error'
});
this.dispatchEvent(toastEvent);
});
}
}
Video
Video does not exists.