Book Image

Force.com Enterprise Architecture

By : Andrew Fawcett
Book Image

Force.com Enterprise Architecture

By: Andrew Fawcett

Overview of this book

Table of Contents (20 chapters)
Force.com Enterprise Architecture
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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_SObjectUnitOfWork uow)
{
  // Apply championship points to given contestants 
  for(Contestant__c contestant : 
    (List<Contestant__c>) Records)
  {
    // Determine points to award for the given position
    ChampionshipPoints__c pointsForPosition = ChampionshipPoints__c.getInstance(String.valueOf(contestant.RacePosition__c));
    if(pointsForPosition!=null)
    {
      // Apply points and register for udpate with uow
      contestant.ChampionshipPoints__c...