mitchspano/apex-trigger-actions-framework

Example regarding avoid repeated queries does not work (anymore)

sfdcschwabe opened this issue · 3 comments

Expected Behavior

Working example. :)

Actual Behavior

The runtime error display an error message and describe that an interface is missing for the outer class.

Steps to Reproduce the Problem

  1. Copy the example from avoid repeated queries (https://github.com/mitchspano/apex-trigger-actions-framework#avoid-repeated-queries) into a Trigger Action and execute it

Specifications

  • Version:
  • Platform:

Platform: Scratch org
Version: Finalizer #118

By trying to create an opportunity following error pop up:

OpportunityTrigger: execution of BeforeInsert caused by: MetadataTriggerHandler.MetadataTriggerHandlerException: Please check the Trigger Action Custom Metadata for the BEFORE_INSERT context on the Opportunity sObject. The TA_Opportunity_Queries class does not implement the Trigger Action interface specified for the BEFORE_INSERT context. Class.MetadataTriggerHandler.handleException: line 327, column 1 Class.MetadataTriggerHandler.validateType: line 318, column 1 Class.MetadataTriggerHandler.executeActions: line 253, column 1 Class.MetadataTriggerHandler.beforeInsert: line 73, column 1 Class.TriggerBase.run: line 122, column 1 Trigger.OpportunityTrigger: line 10, column 1

Thanks for raising this issue.

The top level TA_Opportunity_Queries class is not supposed to implement the interface. The documentation states:


Note: In the example above, the top level class is the implementation of the Singleton pattern, but we also define an inner class called Service which is the actual Trigger Action itself. When using this pattern for query management, the Apex_Class_Name__c value on the Trigger_Action__mdt row would be TA_Opportunity_Queries.Service.


What does your Trigger_Action__mdt custom metadata row look like? If it has Apex_Class_Name__c = 'TA_Opportunity_Queries', then that would be the source of the issue; please update the value to 'TA_Opportunity_Queries.Service'.

Thank you for the hint. This fixed my problem.