AfterUndelete.Bypassable
Skips a Writer or Dispatcher for the whole chunk when a condition holds, such as a static flag or a custom permission.
Interface
apex
public class AfterUndelete {
public interface Bypassable {
Boolean bypassOnAfterUndeleteWhen();
}
}bypassOnAfterUndeleteWhen(): called once per chunk, before parents load; not called when metadata orTriggerOrchestrator.bypass()already skips the handler. Returnstrueto skip this handler for this chunk.
Example
apex
public with sharing class ContactWriter implements AfterUndelete.Writer, AfterUndelete.Bypassable {
public static Boolean isDisabled = false;
public Boolean bypassOnAfterUndeleteWhen() {
return ContactWriter.isDisabled;
}
public Boolean writeOnAfterUndeleteWhen(TriggerHandler.UndeleteRecord record) {
return record.isNotNull(Contact.AccountId);
}
public void writeOnAfterUndelete(TriggerHandler.UndeleteRecord record, TriggerHandler.UnitOfWork unitOfWork) {
unitOfWork.toInsert(new Task(WhatId = ((Contact) record.getNewSObject()).AccountId, Subject = 'Review contact'));
}
}Good to Know
- No records. The method answers for the whole chunk. 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
finallyblock. - Outside the error handling. An exception here is not logged, ContinueOnError does not apply, and the restore fails.
- Inner classes.
TriggerOrchestrator.bypass().handler(X.class)and.orchestrator(X.class)never match an inner class. Use aTriggerHandler__mdtrecord or this interface. - Only this context. Metadata and
bypass().handler(X.class)switch a class off in every context. ImplementAfterUndelete.Bypassableto skip only the restore. More switches: Bypassing.
