In the following example (also included in the sample code for this chapter), a new Custom Object is created to represent the teams that participate in the races. The Driver object has gained a new Lookup field called Team to associate the drivers with their teams.
Leveraging the compliance framework built earlier, a Verify Compliance button for the Team records is also added to provide a means to check certain aspects of the team that are compliant (such as the maximum distance cars can cover during testing), as well as whether all the drivers in this team are still compliant (reusing the existing code).
The following components have been added to the application to support this example:
- A new Team object and tab
- A new Testing Distance number field with a length of 6 on the Team object
- A new Team lookup field on the Driver object
- A new Teams Domain class
Being able to call between the Domain layer classes permits the driver compliance-checking code to continue to be reused at the Driver level as well as from the Team level. This Domain class example shows the Teams Domain class calling the Drivers Domain class:
public class Teams extends fflib_SObjectDomain implements ComplianceService.ICompliant {
public List<ComplianceService.VerifyResult> verifyCompliance() { // Verify Team compliance List<ComplianceService.VerifyResult>teamVerifyResults = new List<ComplianceService.VerifyResult>(); for(Team__c team : (List<Team__c>) Records) { ComplianceService.VerifyResulttestingDistance = new ComplianceService.VerifyResult(); testingDistance.ComplianceCode = '22.5'; testingDistance.RecordId = team.Id; testingDistance.passed = team.TestingDistance__c!=null ? team.TestingDistance__c <= 15000 : true; testingDistance.failureReason = testingDistance.passed ? null : 'Testing exceeded 15,000km'; teamVerifyResults.add(testingDistance); } // Verify associated Drivers compliance teamVerifyResults.addAll( new Drivers( new DriversSelector().selectDriversByTeam( new Map<Id, SObject(Records).keySet()))
.verifyCompliance());
return teamVerifyResults; } }
The following screenshot shows the new Team object and Compliance Checker component added to the Team page using Lightning App Builder. The team record and related driver records have compliance issues. For the team record, there is an invalid Testing Distance value greater than 15,000 km. The FIA Super License field on the Driver record for Lewis Hamilton, which is unchecked, is not shown:
As we conclude this chapter, the final step is to package the changes in a new version of the FormulaForce package, as described in the next section.