+ Start a Discussion
JN22JN22 

Test Class to Cover Single Trigger

Hello,

I have a test class that currently covers multiple triggers.  How can I get this calss to cover only 1 trigger?  It's causing an issue because some of the triggers are Before Insert triggers and others are After Insert so I am getting Null Pointer Exception errors because of it.  Thanks,
Best Answer chosen by JN22
Vishant ShahVishant Shah
You need to define this class

public class triggerControl{

     public static stopExecution;

}

in your class set the

triggerControl.stopExecution = true;

in your triggers which dont need execution check if triggerControl.stopExecution = false and execute code,

in the trigger you need executing check for triggerControl.stopExecution = true and execute code..

Hope this helps

Ta
Vish

All Answers

Vishant ShahVishant Shah
You will need to create a new class with a static boolean variable. Set this to true and check for the value in all the triggers,  Check for false in the trigger you want to control.

This should solve your issue.

Vishant
JN22JN22
Hi Vishant,

Thanks for the reply.  So I need to add code to each trigger that sets the boolean value and checks that class?  Then I need to do this for every other trigger as well to cover individually?  Thanks,
Vishant ShahVishant Shah
You need to define this class

public class triggerControl{

     public static stopExecution;

}

in your class set the

triggerControl.stopExecution = true;

in your triggers which dont need execution check if triggerControl.stopExecution = false and execute code,

in the trigger you need executing check for triggerControl.stopExecution = true and execute code..

Hope this helps

Ta
Vish
This was selected as the best answer
JN22JN22
Thanks, that works!
Vishant ShahVishant Shah
Awesome, Glad that worked.

Ta
Vish