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
jasonsfdcjasonsfdc 

Using APEX Classes from within a trigger

I have the following business scenario.  I have a condition on three different objects that results in a trigger being executed.  For each object, the trigger fires the same logic -- checking field values, etc, and then pulling in some external data located on another object, filling in fields, etc.  Writing the trigger to perform this action is fairly straightforward.
 
However, what I would ideally like to do is use a single class that handles the processing and then have each trigger execute the class.  The problem is the SObjects are different and when I invoke the method and then attempt to use the SObject, I am unable to "cast" it correctly.
 
Has anyone done this?  If so, could you provide a sample piece of code for the invoking trigger (method signature) and how the SObject is cast to the appropriate concrete value in the Class to utilize in processing?
 
Any assistance is greatly appreciated!
 
(In reading the Cookbook, I have the impression it "should" be possible, but wasn't able to find an example of how...)
 
Thanks,

Jason