---
url: https://trigger.beyondthecloud.dev/before-update.md
description: >-
  Before update in Trigger Lib - set fields with a Populator or reject changes
  with a Validator, with the old and new values side by side.
---

# BeforeUpdate

Runs in **before update**, before the changes are saved, with the old and new values side by side.

## Roles {#roles}

* [Populator](/before-update/populator): set, derive or clear fields, usually when another field changed.
* [Validator](/before-update/validator): reject a change with an error message.

## Register {#register}

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

```apex
public with sharing class ContactTriggerOrchestrator implements TriggerOrchestrator.BeforeUpdate {
    public List<BeforeUpdate.Handler> beforeUpdateHandlers() {
        return new List<BeforeUpdate.Handler>{ new ContactPopulator(), new ContactValidator() };
    }
}
```

## Rules {#rules}

* **The old row is read-only.** Writing to `getOldSObject()` or calling `addError` on it throws a `FinalException` that no `catch` stops. The update fails.
* **Updates re-enter.** A later update of the same records in the transaction runs BeforeUpdate again. When a record comes back to a Populator after 3 passes, the run logs an error and the Populator keeps running. A Validator runs on every pass.
* **Lookups hold only the Id.** `((Contact) record.getNewSObject()).Account` is null. Declare a [ParentQuery](/before-update/add-ons/parent-query) and read `record.getNewParent(Contact.AccountId)`.
* **One role per class.** A class that implements both roles runs only as a Populator. List Populators first, so Validators see the values they set.

::: warning
No DML. If a handler runs DML or publishes an event, the library throws. Set fields with `record.put`, and change other records from an [AfterUpdate.Writer](/after-update/writer).
:::
