What are recursive triggers How can we avoid the recursion problem?
Best practice for triggers: Logic-less Triggers – use Helper classes to handle logic. Code coverage 100% Handle recursion – To avoid the recursion on a trigger, make sure your trigger is getting executed only one time. You may encounter the error : ‘Maximum trigger depth exceeded’, if recursion is not handled well.
Can a trigger call itself?
Trigger Self-Recursion By default, a trigger does not call itself recursively. That is, an update trigger does not call itself in response to a second update to the same table within the trigger. The allow nested triggers configuration variable must also be enabled for self-recursion to occur.
When is the maximum trigger depth exceeded in Salesforce?
Normally ‘Maximum Trigger depth Exceeded’ error occurs when a trigger recursively invoke triggers more than 16 times (Maximum stack depth). To avoid this we have to break the recursive call. One way is to use static boolean flag whereever your business logic permits.
When does the recursion of a trigger stop?
With this approach in place the recursion stops once the trigger is called a second time, as it does not attempt to insert a third record. The result is for every one record a second additional record is created and the recursion is avoided.
How are static variables used in recursive triggers?
Use static variables to store information that is shared within the confines of the class. All instances of the same class share a single copy of the static variables. For example, all triggers that are spawned by the same transaction can communicate with each other by viewing and updating static variables in a related class.
Why did apex trigger insertopp cause an unexpected exception?
Apex trigger insertOpp caused an unexpected exception, contact your administrator: insertOpp: execution of AfterUpdate caused by: System.DmlException: Update failed.