+ Start a Discussion
Data Migration 5Data Migration 5 

Test Class for trigger with Static Variable

I have written a trigger (after update) on Opportunity. There are existing triggers on opportunity that fireup on opportunity update. To avoid infinite loop, I have used static variable in my trigger to avoid triggering twice. Now, while writing the test class, I have created new opportunity. But when I try to update that opportunity to make the trigger fire, my code in trigger is not getting executed as static variable has already been set to true. How to make my trigger fire now?
Alexander TsitsuraAlexander Tsitsura
hi, 
u can change static variable in unit test(if it is private use @TestVisible anotation) after created new opportunity. But i can not recomended use static variable for it. This is not working when u processing more that 200 records. For example, if u proccessing 300 records, trigger divide 300 records on two chunks(200 and 100 records), and after processed first chunk static varaible not reseted. I recomended use static structure for determine records id who are processing before