You need to sign in to do that
Don't have an account?

How to pass trigger instance to handler class?
Hi. I want to code for a trigger in Apex but I want the logic to reside in a handler class and have only one statement in the trigger itself which references a static method in the handler class. Basically something like this:
trigger myTrigger on sObject (after update, after insert, after delete, after undelete){
public class HandlerClass{
Is this possible and what would I need to pass from the trigger to the Handler as the args[] to make this work? Any help would be much appreciated. Thanks.
trigger myTrigger on sObject (after update, after insert, after delete, after undelete){
HandlerClass.executeTriggerLogic(args[]);
}public class HandlerClass{
public static void executeTriggerLogic (args[])
{
//trigger logic
{
//other methods...
}//other methods...
Is this possible and what would I need to pass from the trigger to the Handler as the args[] to make this work? Any help would be much appreciated. Thanks.
You need to pass correct Trigger context variables associated with each of your trigger events. In your case you should use the following
For your reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm
I hope the above answer is helpful for you.
Regards
Karthikeyan