mitchspano/trigger-actions-framework

When apex trigger actions have generic list<SObject> as parameters, calling 'getSObjectType' on entry-criteria filtered triggerNew returns null

Opened this issue · 2 comments

Expected Behavior

If the parameters for an apex action are generic 'List', calling 'getSObjectType' on those parameters should return the records' SObject type.

Actual Behavior

If any entry criteria is set, calling getSObjectType returns null.

Steps to Reproduce the Problem

  1. Create an apex trigger action where the parameters are generic 'List' and entry criteria is blank.
  2. calling 'getSObjectType' on triggerNew returns the SObjectType as expected
  3. Add any entry criteria to the action
  4. calling getSObjectType now returns null

Specifications

  • Version: 0.3.3
  • Platform: Developer Edition

Simple Trigger Action Class to Replicate

public with sharing class DynamicSObjectTriggerAction implements TriggerAction.BeforeUpdate {
  public void beforeUpdate(List<SObject> triggerNew, List<SObject> triggerOld) {
      Schema.SObjectType sobjectType = triggerNew.getSObjectType();
      
      // 'sobjectType' will be 'null' if any filter criteria is specified
      System.debug('SObjectType from triggerNew: ' + sobjectType);
  }
}

The Trigger Record Subclass to Replicate

global class AccountTriggerRecord extends TriggerRecord {
  global Account record {
    get {
      return (Account) this.newSObject;
    }
  }
  global Account recordPrior {
    get {
      return (Account) this.oldSObject;
    }
  }
}

Please share the minimum viable reproduction classes for the trigger action and the subclass of TriggerRecord that lead to this issue.

Please share the minimum viable reproduction classes for the trigger action and the subclass of TriggerRecord that lead to this issue.

I've updated the issue description with those classes. I'm happy to provide a fix if this is indeed an issue and it would be helpful.