Bugfix in triggerhandler

This commit is contained in:
WimVelzeboer
2021-12-09 12:10:40 +00:00
parent 9f18f4065c
commit 9822d06610
3 changed files with 21 additions and 1 deletions
@@ -89,6 +89,14 @@ public virtual inherited sharing class fflib_TriggerActionConfig
return this.sequence; return this.sequence;
} }
/**
* @return Returns the SObjectType linked to the trigger action
*/
public SObjectType getSObjectType()
{
return this.sObjectType;
}
/** /**
* @return Returns TRUE if the trigger action should be executed in a dedicated Queueable context * @return Returns TRUE if the trigger action should be executed in a dedicated Queueable context
*/ */
@@ -107,7 +107,9 @@ public virtual with sharing class fflib_TriggerHandler
fflib_UnitOfWork unitOfWork = new fflib_UnitOfWork(); fflib_UnitOfWork unitOfWork = new fflib_UnitOfWork();
for (fflib_ITriggerActionConfig triggerActionConfig : configs) for (fflib_ITriggerActionConfig triggerActionConfig : configs)
{ {
if (isValidExecutionContext(ctx, triggerActionConfig) == false) continue; if (isValidExecutionContext(ctx, triggerActionConfig) == false
||
isValidSObjectType(triggerActionConfig, ctx) == false) continue;
fflib_ITriggerAction triggerAction = getTriggerActionInstance(triggerActionConfig); fflib_ITriggerAction triggerAction = getTriggerActionInstance(triggerActionConfig);
@@ -130,6 +132,11 @@ public virtual with sharing class fflib_TriggerHandler
return config.hasTriggerContext(ctx.getTriggerOperation()); return config.hasTriggerContext(ctx.getTriggerOperation());
} }
private Boolean isValidSObjectType(fflib_ITriggerActionConfig triggerActionConfig, fflib_ITriggerContext ctx)
{
return triggerActionConfig.getSObjectType() == ctx.getRecords().get(0).getSObjectType();
}
private fflib_ITriggerAction getTriggerActionInstance(fflib_ITriggerActionConfig triggerActionConfig) private fflib_ITriggerAction getTriggerActionInstance(fflib_ITriggerActionConfig triggerActionConfig)
{ {
if (triggerActionConfig.isStateful() if (triggerActionConfig.isStateful()
@@ -39,6 +39,11 @@ public interface fflib_ITriggerActionConfig
*/ */
Integer getSequence(); Integer getSequence();
/**
* @return Returns the SObjectType linked to the trigger action
*/
Schema.SObjectType getSObjectType();
/** /**
* @param triggerOperation The Trigger operation to validate the configuration against. * @param triggerOperation The Trigger operation to validate the configuration against.
* *