AfterDelete.ContinueOnError
Log and swallow the handler's exceptions, so later handlers still run and the delete goes on.
Signature
apex
public interface ContinueOnError {
}AfterDelete.ContinueOnError has no methods: implementing it is the whole opt-in.
Example
apex
public with sharing class ContactWriter implements AfterDelete.Writer, AfterDelete.ContinueOnError {
public Boolean writeOnAfterDeleteWhen(TriggerTypes.DeleteRecord record) {
return record.isNotNull(Contact.AccountId);
}
public void writeOnAfterDelete(TriggerTypes.DeleteRecord record, TriggerTypes.UnitOfWork unitOfWork) {
unitOfWork.toInsert(new Task(WhatId = ((Contact) record.getOldSObject()).AccountId, Subject = 'Review contact'));
}
}Rules
- The handler stops for the chunk. Its other records and its Finalizer are skipped.
- Add a Logger. Without one, a swallowed exception leaves no trace.
- A Writer gets the automatic unit of work. Unless it implements OwnUnitOfWork, its writes commit right after it, so a failure never touches other Writers' writes.
WARNING
Some errors still fail the delete. Library exceptions, System.LimitException, the FinalException from writing a trigger row and exceptions outside the handler's own methods, such as bypassOnAfterDeleteWhen() or the final commit, are never swallowed.
