Force-Framework

Mark Brennand

Assertion

global with sharing class Assertion
DescriptionCopyright (c) 2025 Mark Brennand, released under MIT License.

Class providing programmatic Assertions.

The Salesforce Assert class is great, but it throws an Exception which cannot be caught. So, in reality, is only useful for unit tests.

Ancestor methods should be able to catch assertion errors so they can be handled. For example, the Asynchronous API must be able to catch any assertion failures during the processing of a job so it can record the caught Exception. With the Salesforce assertion Exception, that is not possible.

The APIs in the Force Framework all use this class to check assertions, allowing any Exception to be caught.
AuthorMark Brennand

Assertion.AssertionException

global with sharing class AssertionException extends Exception
DescriptionException thrown when an assertion fails.