Notes
HTML
<template>
<!-- Success or Error message -->
<template if:true={message}>
<p class="slds-text-color_success">{message}</p>
</template>
<template if:true={errorMessage}>
<p class="slds-text-color_error">{errorMessage}</p>
</template>
</template>
JavaScript
import { LightningElement, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import deleteRecord from '@salesforce/apex/AccountDeletionController.deleteAllAccounts';
export default class DeleteAllAccounts extends LightningElement {
message;
errorMessage;
connectedCallback() {
this.deleteAllAccounts();
}
// Call Apex to delete all Account records
deleteAllAccounts() {
deleteRecord()
.then(() => {
// Show success message
this.message = 'All accounts deleted successfully!';
this.errorMessage = undefined;
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'All accounts deleted successfully!',
variant: 'success',
})
);
})
.catch((error) => {
// Show error message
this.message = undefined;
this.errorMessage = 'Error: ' + error.body.message;
this.dispatchEvent(
new ShowToastEvent({
title: 'Error',
message: error.body.message,
variant: 'error',
})
);
});
}
}
Apex
public with sharing class AccountDeletionController {
@AuraEnabled
public static void deleteAllAccounts() {
List<Account> accountsToDelete = [SELECT Id FROM Account LIMIT 10000]; // Limit to 10,000 for bulk deletion
if (!accountsToDelete.isEmpty()) {
delete accountsToDelete;
}
}
}
Meta XML
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>56.0</apiVersion> <!-- Make sure the API version matches the Salesforce version you're using -->
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordAction</target> <!-- This makes it available as a Quick Action -->
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<objects>
<object>*</object> <!-- Or specify Account if you want it to be specific -->
</objects>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>