Implementing custom Domain logic

A Domain class should not restrict itself to containing logic purely related to Apex Triggers. In the following example, the code introduced in the previous chapter to calculate championship points has been refactored into the Contestants Domain class. This is a more appropriate place for it, as it directly applies to the Contestant record data and can be readily shared between other Domain and Service layer code (which we will look at later in this chapter):

public void awardChampionshipPoints(fflib_ISObjectUnitOfWorkuow) { 
   // Apply championship points to given contestants 
   Map<Integer, ChampionshipPoint__mdt> pointsByTrackPosition = 
new ChampionshipPointsSelector().selectAllByTrackPosition(); for(Contestant__c contestant : (List<Contestant__c>) Records) { // Determine points to award for the given position ChampionshipPoint__mdt pointsForPosition =
pointsByTrackPosition.get(
Integer.valueOf(contestant.RacePosition__c)); if(pointsForPosition!=null) { // Apply points and register for udpate with uow contestant.ChampionshipPoints__c =
pointsForPosition.PointsAwarded__c; uow.registerDirty(contestant); } }
}

Note that the Unit Of Work is passed as a parameter here so that the method can register work (record updates) with the calling Service layer method responsible for committing the work. Once again, as with the previous Domain class methods, the Records property is used to access the Contestant records to process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.1.232