BeforeInsert.ContinueOnError
Log and swallow the handler's exceptions, so later handlers still run and the insert goes on.
Signature
apex
public interface ContinueOnError {
}BeforeInsert.ContinueOnError has no methods: implementing it is the whole opt-in.
Example
apex
public with sharing class ContactPopulator implements BeforeInsert.Populator, BeforeInsert.ContinueOnError {
public Boolean populateOnBeforeInsertWhen(TriggerTypes.InsertRecord record) {
return record.isBlank(Contact.LeadSource);
}
public void populateOnBeforeInsert(TriggerTypes.InsertRecord record) {
record.put(Contact.LeadSource, 'Web');
}
}Rules
- The handler stops for the chunk. Its remaining records and its Finalizer are skipped. Values it already set and errors it already attached stay.
- On a Validator, the rest goes unchecked. Records after the failing one are saved unless another handler rejects them.
- Add a Logger. Without one, a swallowed exception leaves no trace.
WARNING
Some exceptions still fail the insert: DML in the handler, a Validator that attaches no error, TriggerTypes.TriggerLibException, System.LimitException, and exceptions in bypassOnBeforeInsertWhen(), queryParentsOnBeforeInsert() or the parent query after a Populator.
