You need to sign in to do that
Don't have an account?
Haystack Certified
Prevent Trigger Recursion with Data Loader in Bulk Mode
I can't seem to get a clear answer to this problem via Google search. What is the best way to prevent trigger recursion with Data Loader in Bulk mode? For example, consider needing to load 500,000 records and there is an After trigger updating the same records that caused the trigger to fire. Any advice?
This should have been handled in your trigger itself.
- Create a static boolean variable in an apex class and set it to TRUE
- At the entry point of your trigger, check for this boolean value (if(<ApexClassName>.<BooleanVariableName>==true)). If it is true, the code assumes it as the first invoke.
- Inside the if condition, set the boolean variable to false
- If the same trigger/actions are called again, the code automatically checks for the boolean and skips the operation as the boolean will be false this time
- This works for both single and bulk updates and if your trigger is bulkied
Refer this link:
https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US
Let me know if i didnt understand your question correctly.
Regards,
Bharathimohan Ramaurthy
Salesforce For All (http://salesforceforall.blogspot.com/)
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.