AfterUndelete.ContinueOnError
Logs and swallows a Writer's or Dispatcher's exceptions. Later handlers still run, and the records are still restored.
Interface
apex
public class AfterUndelete {
public interface ContinueOnError {
}
}AfterUndelete.ContinueOnError has no methods: implementing it is the whole opt-in.
Example
apex
public with sharing class ContactWriter implements AfterUndelete.Writer, AfterUndelete.ContinueOnError {
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
- The handler stops for the chunk. After an exception, it skips its remaining records and its Finalizer.
- A Writer gets a private unit. Unless it implements OwnUnitOfWork, its writes commit right after it. When it throws, its registrations are discarded.
- Some errors still fail the restore.
TriggerOrchestratorExceptionandTriggerHandler.TriggerHandlerExceptionare logged and rethrown. AFinalExceptionorLimitExceptioncannot be caught. - Not everything is covered. Exceptions in
afterUndeleteHandlers(),bypassOnAfterUndeleteWhen(),ownUnitOfWorkOnAfterUndelete(),queryParentsOnAfterUndelete()and the shared commit fail the restore. - Logged only with a Logger. A swallowed exception goes to the org's
TriggerOrchestrator.Loggerimplementation. Without one it leaves no trace. See Errors & Logging.
