Skip to content

BeforeDelete.ContinueOnError ​

Log and swallow the handler's exceptions, so later handlers still run and the delete goes on.

Signature

apex
public interface ContinueOnError {
}

BeforeDelete.ContinueOnError has no methods: implementing it is the whole opt-in.

Example

apex
public with sharing class ContactValidator implements BeforeDelete.Validator, BeforeDelete.ContinueOnError {
    public Boolean addErrorOnBeforeDeleteWhen(TriggerTypes.DeleteRecord record) {
        return record.isTrue(Contact.DoNotCall);
    }

    public void addErrorOnBeforeDelete(TriggerTypes.RejectableDeleteRecord record) {
        record.addError('A Do Not Call contact cannot be deleted.');
    }
}

Rules ​

  • The rest of the handler is skipped. After an exception, this handler's remaining records and its Finalizer are skipped. An exception in a provider stops the handler where the provider is first read.
  • 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.
  • Some errors still fail the delete. Library exceptions, System.LimitException and exceptions outside the handler's own methods, such as bypassOnBeforeDeleteWhen(), queryPriorParentsOnBeforeDelete() or the final commit, are never swallowed.
  • Add a Logger. Without one, a swallowed exception leaves no trace.

WARNING

Never add it to a Validator that guards a delete. A swallowed exception means no error is attached, so the record is deleted.