Improvements to the trigger handler

Ability to disable trigger action in meta-data, and adds a stateful option

Signed-off-by: WimVelzeboer <wimvelzeboer@protonmail.com>
This commit is contained in:
WimVelzeboer
2021-10-28 15:35:28 +01:00
parent ed87378fba
commit ef77fad3ed
8 changed files with 131 additions and 6 deletions
@@ -66,7 +66,6 @@ public virtual inherited sharing class fflib_TriggerActionConfig
else if (triggerAction.ExecutionContext__c == 'Dedicated Queued') this.dedicatedQueued = true;
// Get SObjectType
System.debug('triggerAction: '+triggerAction);
String ObjectTypeApiName =
String.isNotBlank(triggerAction.ObjectType__c)
? triggerAction.ObjectType__r?.QualifiedApiName?.toLowerCase().trim()
@@ -74,6 +73,14 @@ public virtual inherited sharing class fflib_TriggerActionConfig
this.sObjectType = Schema.describeSObjects(new List<String> {ObjectTypeApiName}).get(0).getSObjectType();
}
/**
* @return Returns the Implementation Type of the Trigger Action
*/
public Type getImplementationType()
{
return this.implementationType;
}
/**
* @return Returns the sequence number of the trigger action
*/
@@ -90,6 +97,14 @@ public virtual inherited sharing class fflib_TriggerActionConfig
return (this.dedicatedQueued != null && this.dedicatedQueued);
}
/**
* @return Returns TRUE if the trigger action needs to be kept in memory and reused by the next TriggerHandler run
*/
public Boolean isStateful()
{
return this.stateful;
}
/**
* @return Returns TRUE if the trigger action can be executed in an Queueable context
*/
@@ -107,4 +122,15 @@ public virtual inherited sharing class fflib_TriggerActionConfig
{
return (fflib_ITriggerAction) implementationType.newInstance();
}
public Boolean hasTriggerContext(TriggerOperation triggerOperation)
{
return (triggerOperation == System.TriggerOperation.BEFORE_INSERT && beforeInsert)
|| (triggerOperation == System.TriggerOperation.BEFORE_UPDATE && beforeUpdate)
|| (triggerOperation == System.TriggerOperation.BEFORE_DELETE && beforeDelete)
|| (triggerOperation == System.TriggerOperation.AFTER_DELETE && afterDelete)
|| (triggerOperation == System.TriggerOperation.AFTER_INSERT && afterInsert)
|| (triggerOperation == System.TriggerOperation.AFTER_UNDELETE && afterUndelete)
|| (triggerOperation == System.TriggerOperation.AFTER_UPDATE && afterUpdate);
}
}