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