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

Recursive trigger issue
I have a trigger on contact which fires after insert and update. I have created a helper class where all my logic exist. I have created a static set at class level . I add values to this SET inside my onInsertAndUpdate method so as not to process those records again. At the top of my method I check if this static variable is null and only then do additional logic in the onInsertAndUpdate method. The issue I'm having is that there are multiple workflow rules that fire and update contact record which result in this trigger firing multiple times. I checked the debug log and looks like the static variable == null is true every time this onInsertAndUpdate is called again and hence it goes though rest of the logic. Please help me understand what is going on.
Thanks.
Thanks.
public without sharing class ContactTriggerHandler { private boolean m_isExecuting = false; private integer BatchSize = 0; public static Set <String> EmailSet = null; public ET_ContactTriggerHandler (boolean isExecuting, integer size){ m_isExecuting = isExecuting; BatchSize = size; } public void onInsertAndUpdate (Contact[] updatedContacts, Map<ID, Contact> OldMap) { if(EmailSet==null){ //do something EmailSet.add(something); } } }
http://amitsalesforce.blogspot.in/2015/03/how-to-stop-recursive-trigger-in.html
Solution :-
you can create a class with a static Boolean variable with default value true. In the trigger, before executing your code keep a check that the variable is true or not. Once you check make the variable false.
You can check below post for trigger framwork
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Please let us know if this will help you
Thanks
Amit Chaudhary