Domain layer interactions

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).

This will be done by adding the compliance verification code in the new Teams Domain class call and by delegating logic to the Drivers Domain class method to implement the same logic for drivers within the team.

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
You don't always have to create an Apex Trigger that calls the fflib_SObjectDomain.triggerHandler method if you don't plan on overriding any of the Apex Trigger event handler methods.

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 bulkification guideline applied to the Domain layer is being leveraged in the preceding code, as the Drivers Domain class logic was reused directly, with no changes, from the Teams Domain class. Also, note that the implementation of the Drivers Domain class was, and is, still unaware of the split of drivers by team.

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.

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

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