Skip to content

Creating Apex Trigger #294

@michelhabib

Description

@michelhabib

Hi Andrew, @afawcett
I am trying to create an Apex Trigger dynamically using your fantastic wrapper, I am building a managed package for the AppExchange.
After looking everywhere, here are the suggestions I found:-
1- Create the Trigger statically. Not a solution in my case, since I may need different triggers on different objects with different events - based on user input.
2- Use Tooling API. I am reading comments that this is not going to work in Production Org, hence will not work through Managed packages like mine, and I cannot validate this yet.
Can I use Tooling API through Managed Package Code? It still sounds like a hard to implement solution.
3- Use Metadata API (with the Apex Wrapper here) to deploy Apex Triggers? I am still looking for examples on how to do that, but it sounds like an interesting solution if it uses the Apex Wrapper library here, as I am using this library everywhere.
Tip: I found references to your open source DLRS and I expect this class to have the required code:
https://github.com/SFDO-Community/declarative-lookup-rollup-summaries/blob/main/dlrs/main/classes/RollupController.cls
4- Use Metadata API to dynamically create Flows/Apex Actions. Knowing that my trigger execution code itself can be static, but not the trigger definition, so the Apex Action can be the same for all triggers/events. An out of the box idea I thought about, but I am afraid to go this path and hit any limitations.

I apologize for not adding links or code here (yet), but as I am uncovering the solution, I promise to post a working example :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions