To resolve recursive trigger please follow the below steps,
1. Create a class with the Boolean variable and set
this as true to avoid Recursive trigger.
- public class RecursiveHandler
- {
- public static Boolean isNotRecursive = true;
- }
2. Check the Boolean flag value before process your
condition and set the flag value to false at the beginning of your process. Once if you set this
false, the recursion will stop.
Hope the above coding will helpful to solve recursive trigger error.
- trigger DuplicateRecordMaker on Account (after insert, after update)
- {
- List<Account> accounts = new List<Account>();
- if(RecursiveHandler.isNotRecursive)
- {
- RecursiveHandler.isNotRecursive = false;
- for(Account currentAccount : Trigger.New)
- {
- Account acc = new Account();
- acc.Name = currentAccount.Name;
- accounts.add(acc);
- }
- insert accounts;
- }
- }
Hope the above coding will helpful to solve recursive trigger error.