Link Search Menu Expand Document

This short blog highlights a set of features added by the community. It is really pleasing to see this library continue to get great contributions. Thank you!

Added methods for detecting changed records with given fields in the Domain layer (fflib_SObjectDomain)

First up is a great new optimization feature for your Domain class methods from Nathan Pepper aka MayTheSForceBeWithYou based on a suggestion by Daniel Hoechst. Where applicable its a good optimization practice to considering comparing the old and new values of fields relating to processing you are doing in your Domain methods to avoid unnecessary overheads. The new fflib_SObjectDomain.getChangedRecords method can be used as an alternative to the Records property to just the records that have changed based on the field list passed to the method.

// Returns a list of Account where the Name or AnnaulRevenue has changed  
List<Account> accounts =  
 (List<Account>) getChangedRecords(  
 new List<SObjectField> { Account.Name, Account.AnnualRevenue });  

Supporting EventBus.publish(list<SObject>) in Unit of Work (fflib_SObjectUnitOfWork)

Platform Events are becoming ever popular in many situations. If you regard them as logically part of the unit of work your code is performing, this enhancement from Chris Mail is for you! You can now register platform events to be sent based on various scenarios. Chris has also provided bulkified versions of the following methods, nice!

 /**  
  * Register a newly created SObject (Platform Event) instance to be published when commitWork is called  
  *  
  * @param record A newly created SObject (Platform Event) instance to be inserted during commitWork  
  **/  
 void registerPublishBeforeTransaction(SObject record);  
 /**  
  * Register a newly created SObject (Platform Event) instance to be published when commitWork has successfully  
  * completed  
  *  
  * @param record A newly created SObject (Platform Event) instance to be inserted during commitWork  
  **/  
 void registerPublishAfterSuccessTransaction(SObject record);  
 /**  
  * Register a newly created SObject (Platform Event) instance to be published when commitWork has caused an error  
  *  
  * @param record A newly created SObject (Platform Event) instance to be inserted during commitWork  
  **/  
 void registerPublishAfterFailureTransaction(SObject record);  

Add custom DML for Application.UnitOfWork.newInstance call (fflib_Application)

It’s been possible for a while now to override the default means by which the fflib_SObjectUnitOfWork.commitWork method performs DML operations (for example if you wanted to do some additional pre/post processing or logging). However, if you have been using the Application class pattern to access your UOW (shorthand and helps with mocking) then this has not been possible. Thanks to William Velzeboer you can now get the best of both worlds!

fflib_SObjectUnitOfWork.IDML myDML = new MyCustomDMLImpl();  
fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newIntance(myDML);  

Added methods to Unit of Work to be able to register record for upsert (fflib_SObjectUnitOfWork)

Unit Of Work is a very popular class and receives yet another enhancement in this batch from Yury Bondarau. These two methods allow you to register records that will either be inserted or updated as automatically determined by the records having an Id populated or not, aka a UOW upsert.

 /**  
  * Register a new or existing record to be inserted or updated during the commitWork method  
  *  
  * @param record An new or existing record  
  **/  
 void registerUpsert(SObject record);  
 /**  
  * Register a list of mix of new and existing records to be upserted during the commitWork method  
  *  
  * @param records A list of mix of existing and new records  
  **/  
 void registerUpsert(List&lt;SObject&gt; records);  
 /**  
  * Register an existing record to be deleted during the commitWork method  
  *  
  * @param record An existing record  
  **/  

Alleviates unit-test exception when Org’s email service is limited

Finally, long term mega fan of the library John Storey comes in with an ingenious fix to an Apex test failure which occurs when the org’s email deliverability’s ‘Access Level’ setting is not ‘All Email’. John leveraged an extensibility feature in the Unit Of Work to avoid the test being dependent on this org config all  while not losing any code coverage , sweet!

Last but not least, thank you Christian Coleman for fixing those annoying typos in the docs! :-)