mitchspano/apex-trigger-actions-framework

Adding framework to Managed Package

ianpadrick opened this issue · 6 comments

Mitch, have you seen this added to a managed package before? If so, it seems like there would be a number of areas that would need to be updated with a namespace.

Thanks in advance!

Hey Ian - I have not added this to a managed package, however Apex classes which include a namespace can be used within the framework, so 3rd party code can be injected into the framework if the authors provide public methods for their trigger logic.

Usage of something like the Trigger Actions Framework with dynamic metadata based injection for trigger logic is the only way to allow multiple managed packages share a single injection point for a shared sObject such as Case or Opportunity. Without it, package authors must create their own trigger thus creating a second injection point for synchronous trigger logic.

If you want to be able to use this as part of a 3rd party package, I can create an unlocked package of the Trigger Actions Framework (probably should do that anyways) - would you be able to specify that as a dependency the sfdx-project.json for your project? I'm not sure if managed packages can depend on unlocked packages...?

We're using the 1GP packaging method as we've run into some unknown Salesforce errors with the 2GP package that the Salesforce Tier 3 support team is currently looking into for us.

I noticed in the sObject Trigger Setting there is a field for the Object Namespace which I have tried as well with no luck.

The standard object Trigger we have for Contact is working fine, but none of our Custom Objects are working.

The framework supports managed package sObjects without issues.

  1. Install Field Trip:
    https://app-saas-1234-dev-ed.lightning.force.com/packagingSetupUI/ipLanding.app?apvId=04t2G000000kaa0QAA&src=U
  2. Install Trigger Actions Framework:
sfdx force:source:deploy -p trigger-actions-framework
  1. Create trigger, trigger action, and corresponding custom metadata:
trigger FieldAnalysisTrigger on Field_Trip__Field_Analysis__c (before insert) {
  new MetadataTriggerHandler().run();
}

public with sharing class TA_FieldTripTest implements TriggerAction.BeforeInsert {
  public void beforeInsert(List<Field_Trip__Field_Analysis__c> newList) {
    throw new IllegalArgumentException('Oh no mr Bill!');
  }
}

image

  1. Perform dml operation
insert new Field_Trip__Field_Analysis__c();
Line: 1, Column: 1System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AnalysisTrigger: execution of BeforeInsert caused by: System.IllegalArgumentException: Oh no mr Bill! Class.TA_FieldTripTest: line 3, column 1 Class.MetadataTriggerHandler: line 221, column 1 Class.MetadataTriggerHandler: line 28, column 1 Class.TriggerBase.run: line 46, column 1 Trigger.AnalysisTrigger: line 2, column 1: []

image

Thanks for this Mitch, we were including the "__" in the Namespace section but this help cleared it up - very much appreciated!