Services calling services
In the previous chapter, I described a reuse use case around a FormulaForce application feature that awards championship points to contestants. We imagined the first release of the application providing a Custom Button only on the Contestant detail page and then the second release also providing the same button but on the Race detail page.
In this part of the chapter, we are going to implement the respective service methods, emulating this development cycle and, in turn, demonstrating an approach to call between Service layer methods, passing the Unit Of Work correctly.
First, let's look at the initial requirement for a button on the Contestant detail page; the method in the ContestantService
class looks like this:
public static void awardChampionshipPoints(Set<Id> contestantIds)
{
fflib_SObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
for(Contestant__c contestant :
new ContestantsSelector().selectById(contestantIds))
{
// Determine...