---
url: https://trigger.beyondthecloud.dev/before-delete.md
description: >-
  Before delete in Trigger Lib - block a delete with a Validator, or change
  related records with a Writer while the rows and their links still exist.
---

# BeforeDelete

Runs in **before delete**, before records are removed.

## Roles {#roles}

* [Validator](/before-delete/validator): block a delete with `addError`.
* [Writer](/before-delete/writer): change other records or publish events through a unit of work.

## Register {#register}

Implement `TriggerOrchestrator.BeforeDelete` on the orchestrator and return the handlers from `beforeDeleteHandlers()`. List order is run order. The trigger must list `before delete` and call `TriggerOrchestrator.run(new ContactTriggerOrchestrator())`.

```apex
public with sharing class ContactTriggerOrchestrator implements TriggerOrchestrator.BeforeDelete {
    public List<BeforeDelete.Handler> beforeDeleteHandlers() {
        return new List<BeforeDelete.Handler>{ new ContactValidator(), new ContactWriter() };
    }
}
```

## Rules {#rules}

* **Writes land before the delete.** The shared unit of work commits after the last handler, while the rows and the records that point at them still exist.
* **Cascade deletes fire no child triggers.** Records removed by a cascade delete, such as an account's contacts, do not run their own delete triggers. Read them here with a [RelatedQuery](/before-delete/add-ons/related-query).
* **Merges look like deletes.** The records that lose a merge fire before delete like a plain delete. `MasterRecordId` is set only in [AfterDelete](/after-delete/).
* **One role per class.** A class that implements both roles runs only as a Validator.
