2

I am attempting to design a managed package that performs a specific action on a custom object. I can include the custom object in the package and let customers use that object to access the functionality I am attempting to provide.

Where the challenge comes in is providing the same functionality on one of their existing custom objects. Obviously I can use Batch Apex with Dynamic Apex or even provide an API of sorts, but I want it to be real time and don't want my customers to have to write code if I can avoid it.

Is there any way to dynamically build a trigger that would work on any custom object outside of my own namespace?

I know a solution would be to use the Metadata API to create the trigger on the fly, but then it wouldn't be in my managed package namespace, correct? It would make it difficult for updating the code?

3

So you are correct that there is no way of creating a trigger for objects outside of your namespace dynamically without the need for the metadata API and this would reside outside of your namespace.

A possible workaround is to try including your functionality as a trigger on some intermediary processing object. Then all that requires to happen is when your customer's object is updated it creates a "processing" record which will fire your default trigger and can use some dynamic logic to perform the required updates. They could use a Lightning Process to create one of your records dynamically making the config point and click with it still running in real time (or at least not batched).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.