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
aressaress 

clone recursion

I needed a trigger to create clone of account record on insert.
To avoid recursion I have used a boolean. Is there any method to stop recursion that can be used in this place.
-------------------------------------------------------------------------------------
public class CloneAccountTriggerHandler {
public static Boolean cloneRecord = true;
/**
Method : cloneAccountRecord
Type : Test Method
Description : Method To create Clone of Account Record when inserted
*/
public static List<Account> cloneAccountRecord(List<Account> newAccount){
List<Account> listAccount = new List<Account>();
if(cloneRecord) {
System.debug(newAccount);
cloneRecord = false;
for(Account account : newAccount) {
listAccount.add(account.clone(false));
}
Database.insert(listAccount,false);
}
return listAccount;
}
}
PreyankaPreyanka
Hello Ayisha,
Static Boolean variable is used to stop recursion. Are you facing any issue in the above code because it seems to be working fine to avoid recursion.
 
aressaress
Its working fine. I need to know what are the other methods that i can use to stop recursion