---
url: https://trigger.beyondthecloud.dev/after-undelete/add-ons/bypassable.md
description: >-
  Skip (bypass, disable, turn off) an after undelete Writer or Dispatcher for
  the whole chunk when a condition holds.
---

# AfterUndelete.Bypassable

Skip a handler for the whole chunk when a condition holds, such as a static flag, a batch job or a custom permission.

**Signature**

```apex
public interface Bypassable {
    Boolean bypassOnAfterUndeleteWhen();
}
```

* `bypassOnAfterUndeleteWhen()`: called once per chunk, before parents load. Returns `true` to skip this handler for this chunk.

**Example**

::: code-group

```apex [Skeleton]
public with sharing class ContactWriter implements AfterUndelete.Writer, AfterUndelete.Bypassable {
    public static Boolean isBypassed = false;

    public Boolean bypassOnAfterUndeleteWhen() {
        return ContactWriter.isBypassed;
    }

    public Boolean writeOnAfterUndeleteWhen(TriggerTypes.UndeleteRecord record) {
        return record.isNotNull(Contact.AccountId);
    }

    public void writeOnAfterUndelete(TriggerTypes.UndeleteRecord record, TriggerTypes.UnitOfWork unitOfWork) {
        unitOfWork.toInsert(new Task(WhatId = ((Contact) record.getNewSObject()).AccountId, Subject = 'Review contact'));
    }
}
```

:::

## Rules {#rules}

* **To skip single records, return false from the predicate.**
* **Reset static flags.** A flag lasts the whole transaction, nested saves and later chunks included. Reset it in a `finally` block.
* **Only this context.** [Apex bypasses](/guide/bypasses#apex) cover every context, and `bypass().handler(X.class)` never matches an inner class. A [`TriggerHandler__mdt`](/api/custom-metadata#trigger-handler) record covers the one context it names, for every user.

::: warning
An exception in `bypassOnAfterUndeleteWhen()` is not logged, ContinueOnError does not apply, and the restore fails.
:::
