BeforeUpdate.ContinueOnError
Log and swallow the handler's exceptions, so later handlers still run and the update goes on.
Signature
apex
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(TriggerTypes.UpdateRecord record) {
return record.isChanged(Contact.Email);
}
public void populateOnBeforeUpdate(TriggerTypes.UpdateRecord record) {
record.put(Contact.HasOptedOutOfEmail, false);
}
}Rules
- One failure stops the handler for the chunk. Its remaining records and its Finalizer are skipped. Values it already set stay. To skip only one record, catch the exception in the action.
- Some exceptions still fail the update. DML in the handler, a Validator that attaches no error,
TriggerTypes.TriggerLibException,System.LimitException, theFinalExceptionfrom touching the old row and exceptions from methods that run before the handler's turn, such asbypassOnBeforeUpdateWhen(), are never swallowed. - Add a Logger. Without one, a swallowed exception leaves no trace.
WARNING
Keep it off Validators that protect data. When such a Validator throws, the records it has not checked yet save unchecked.
