fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

Declaration dependency order within Application.cls

Open cropredyHelix opened this issue 6 years ago • 0 comments
trafficstars

A minor point but worthy of an enhancement

If you define your Application class with Application.Domain before Application.Selector, when you attempt to use this construction:

fflib_ISObjectDomain domain = Application.Domain.newInstance(sObjIds);

such as in the ComplianceService example in the 2nd edition book Step 8 page 190, you will get a null pointer exception in inner class fflib_Application.DomainFactory, method newInstance(Set<Id> recordIds)

This is because the Domain factory depends on the Selector factory and as these are static variables, they are initialized in the order of appearance. If declared out of order, the SelectorFactory will be null for this use case.

As folks may populate the Application class from scratch; it is easy to overlook this declaration order dependency (ask me how I know!)

Suggestion: throw a more meaningful exception with a hint as to why this might be happening.

cropredyHelix avatar Feb 26 '19 01:02 cropredyHelix