You need to sign in to do that
Don't have an account?
![aress aress](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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;
}
}
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;
}
}
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.