Routing trigger events to Domain class methods

The following diagram illustrates the flow of execution from the Apex Trigger to the Domain class, triggerHandler, and then to the individual methods:

To help you understand how traditional Apex Trigger events are mapped to the various virtual methods in the base class, the following table describes the code path taken from when the base class's fflib_SObjectDOmai.triggerHandler method is invoked, through to the specific event-based methods that can be overridden by a Domain class:

Trigger context

Base class records property value

Base class handle method called (refer to the following note)

Base class event method(s) called (refer to the following note)

Trigger.isBefore

Trigger.isInsert

Trigger.new

handleBeforeInsert()

onApplyDefaults()

onBeforeInsert()

Trigger.isUpdate

Trigger.new

handleBeforeUpdate(
Map<Id,SObject>
existingRecords)

onBeforeUpdate(
Map<Id,SObject>
existingRecords)

Trigger.isDelete

Trigger.oldMap

handleBeforeDelete()

onBeforeDelete()

Trigger.isAfter

Trigger.isInsert

Trigger.new

handleAfterInsert()

onValidate()

onAfterInsert()

Trigger.isUpdate

Trigger.new

handleAfterUpdate(
Map<Id,SObject>
existingRecords)

onValidate(
Map<Id,SObject>
existingRecords)

onAfterUpdate(
Map<Id,SObject>
existingRecords)

Trigger.isDelete

Trigger.oldMap

handleAfterDelete()

onAfterDelete()

 

Note that handle methods can also be overridden if you wish to implement your own handling. The existingRecords parameter represents the value of Trigger.oldMap.

The base class uses the template method pattern (http://en.wikipedia.org/wiki/Template_method_pattern). This ensures that when overriding the onXXX methods from the base class, you do not need to worry about calling the base class version of the method, as is the typical developer requirement when overriding methods in OOP.

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

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