BeforeUpdate.ContinueOnError
Lets a handler fail without failing the update. The library logs and swallows the exception, and the save goes on.
Interface
apex
public class BeforeUpdate {
public interface ContinueOnError {
}
}BeforeUpdate.ContinueOnError has no methods: implementing it is the whole opt-in.
Example
apex
public with sharing class ContactPopulator implements BeforeUpdate.Populator, BeforeUpdate.ContinueOnError {
public Boolean populateOnBeforeUpdateWhen(TriggerHandler.UpdateRecord record) {
return record.isChanged(Contact.Email);
}
public void populateOnBeforeUpdate(TriggerHandler.UpdateRecord record) {
record.put(Contact.HasOptedOutOfEmail, false);
}
}Good to Know
- One failure stops the handler for the chunk. Its remaining records and its Finalizer are skipped. Values it already set stay, and later handlers still run. To skip only one record, catch the exception in the action.
- Keep it off Validators that protect data. When such a Validator throws, the records it has not checked yet save unchecked.
- Some exceptions still fail the update. These are the library's
TriggerOrchestratorExceptionandTriggerHandler.TriggerHandlerException,LimitException, and theFinalExceptionfrom touching the old row. The DML guard and a Validator that attaches no error throw aTriggerOrchestratorException. - Setup code is not covered. Exceptions in
beforeUpdateHandlers(),bypassOnBeforeUpdateWhen(),maxRecursionDepthOnBeforeUpdate()and the parent queries are never logged and fail the update. - Logging needs a Logger. The swallowed exception goes to your
TriggerOrchestrator.Loggerimplementation, if the org has one. See Errors & Logging.
