Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

TriggerHandler

global virtual inherited sharing class TriggerHandler
DescriptionThis class provides simple trigger handler management with
  • a consistent and efficient pattern for trigger handler implementation.
  • a central dispatch mechanism
  • the ability to disable all trigger handlers that extend this base class
  • the ability to disable a single trigger handler
  • the ability to disable a single feature within a trigger handler
  • optional, automatic CRUD checks
Usage:

 // To implement a trigger handler, create a global class that extends this one
 global with sharing class AccountHandler extends aBoost.TriggerHandler {

   // override TriggerHandler methods needed for your logic...
   global override void onBeforeInsert(SObject[] records) {
     super.onBeforeInsert(records);
     validateFields();
   }

   global override void onBeforeDelete(SObject[] records) {
     super.onBeforeDelete(records);
     preventDeletionInSomeCases();
   }
 }

 // Invoke your handler from the trigger by calling run(). The base class then
 // works its magic, skipping your handler according to custom settings, or
 // calling your overridden method corresponding to the trigger event.
 trigger AccountTrigger on Account(before insert, before update, before delete,
   after insert, after update, after delete, after undelete) {
   new AccountHandler().run();
 }
 

Disabling Triggers

To disable all handlers, set the Enable Triggers Apex BOOST custom setting to false. Note that this can be done for an individual user or profile.

To disable a single handler, create a Boolean Apex BOOST custom setting with the same name as your handler class. This new setting can now be set to false to disable the handler globally or for a single user or profile.

Methods

  handle

global static void handle(Type handlerType)
DescriptionCall this method from your trigger, passing in your handler class.
ThrowsInvalidParameterValueException if handlerType is null

  handle

global static void handle(Type handlerType, Boolean enforceSecurity)
DescriptionCall this method from your trigger, passing in your handler class.
ParameterenforceSecurity: - if true, event handling will check for CRUD permissions and potentially throw a SecurityException.
ThrowsInvalidParameterValueException if handlerType is null
ThrowsTypeException if handlerType does not extend TriggerHandler

  isActive

global static Boolean isActive(String handlerOrFeatureName)
DescriptionDetermine if a trigger handler is active
  1. first, check the status map (a single transaction, while testing)
  2. next, check for a custom field for the handler (a single handler)
  3. finally, check the aBoost.Settings.EnableTriggers__c setting (all handlers)
ThrowsInvalidParameterValueException if handlerOrFeatureName is blank

  onAfterDelete

global virtual void onAfterDelete(SObject[] records)

  onAfterInsert

global virtual void onAfterInsert(SObject[] records)

  onAfterUndelete

global virtual void onAfterUndelete(SObject[] records)

  onAfterUpdate

global virtual void onAfterUpdate(SObject[] records, Map<Id,SObject> existingRecords)

  onApplyDefaults

global virtual void onApplyDefaults(SObject[] records)
DescriptionOverride to set fields to default values

  onBeforeDelete

global virtual void onBeforeDelete(SObject[] records)

  onBeforeInsert

global virtual void onBeforeInsert(SObject[] records)

  onBeforeUpdate

global virtual void onBeforeUpdate(SObject[] records, Map<Id,SObject> existingRecords)

  onValidateAfterInsert

global virtual void onValidateAfterInsert(SObject[] records)
DescriptionOverride to perform validation after insert or undelete

  onValidateAfterUpdate

global virtual void onValidateAfterUpdate(SObject[] records, Map<Id,SObject> existingRecords)
DescriptionOverride to perform validation after update

  run

global virtual void run()
DescriptionCall this method from your trigger to invoke your handler.

  run

global virtual void run(Boolean enforceSecurity)
DescriptionCall this method from your trigger to invoke your handler.
ParameterenforceSecurity: - if true, event handling will check for CRUD permissions and potentially throw a SecurityException.