function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Haystack CertifiedHaystack 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?
BharathimohanBharathimohan
Hello,

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/)
Amit Chaudhary 8Amit Chaudhary 8
Please check below blog. I hope that will help u
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.