deleteRecord accepts a single record ID. To delete multiple records, use Promise.all() or Apex.
This example displays a list of account records with a delete button next to each account name. When a record is deleted successfully, the component displays a toast message and uses refreshApex() to refresh the data provisioned via the Apex @wire.
1import{LightningElement, wire}from 'lwc';2import{ShowToastEvent}from 'lightning/platformShowToastEvent';3import{refreshApex}from '@salesforce/apex';4import{deleteRecord}from 'lightning/uiRecordApi';5import getAccountList from '@salesforce/apex/AccountController.getAccountList';6import{reduceErrors}from 'c/ldsUtils';78export default class LdsDeleteRecord extends LightningElement{9 accounts;10 error;1112 /** Wired Apex result so it can be refreshed programmatically */13 wiredAccountsResult;1415 @wire(getAccountList)16 wiredAccounts(result){17 this.wiredAccountsResult = result;18 if(result.data){19 this.accounts = result.data;20 this.error = undefined;21}else if(result.error){22 this.error = result.error;23 this.accounts = undefined;24}25}2627 async deleteAccount(event){28 const recordId = event.target.dataset.recordid;2930 try{31 await deleteRecord(recordId);32 this.dispatchEvent(33 new ShowToastEvent({34 title: 'Success',35 message: 'Account deleted',36 variant: 'success'37})38);39 await refreshApex(this.wiredAccountsResult);40}catch(error){41 this.dispatchEvent(42 new ShowToastEvent({43 title: 'Error deleting record',44 message: reduceErrors(error).join(', '),45 variant: 'error'46})47);48}49}50}
When you successfully delete a record, any component that’s subscribed to the deleted record via a wire returns a 404 error for that record data.
Don’t call deleteRecord from a record page for a record that you want to delete. The record is deleted and you receive a 404 error with a message “The requested resource does not exist”.
This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.