function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
adamproadampro 

Creating a Trigger from inside a class

I'm trying to create a trigger that will fire on the insert/update of any object a User selects from a picklist in a custom VF page I made. Because it could be any object (either custom or standard), I can't just build a trigger the standard way. What I'm assuming is I'm going to have to pass the data into a class/function and that function will create the trigger. I've been looking around but I can't find a way to build a trigger within a class filled with the rest of the necessary data I need to populate the trigger. Is this even possible? If so, can someone point me in the right direction on this?

 

Thanks!

WizradWizrad

That's not going to be possible Adam.

 

If you can write code that can "write a trigger" the way you need, then you can just write a trigger for each object that works teh way you need.

Ralph CallawayRalph Callaway

This isn't possible with APEX, but could be implemented in Java (or any language with a WSDL parser) externally using the metadata API.  The tricky part is you also need to generate test code to go with it which can be impossible if they have active validation rules.

adamproadampro

Ralph Callaway wrote:

This isn't possible with APEX, but could be implemented in Java (or any language with a WSDL parser) externally using the metadata API.  The tricky part is you also need to generate test code to go with it which can be impossible if they have active validation rules.


Do you possibly have an example of this somewhere? I'm pretty new to Salesforce nor do I have any experience with WSDL.