You need to sign in to do that
Don't have an account?
raghava520
problem with recursive trigger
Hi Experts i am writing a trigger on account object if create contact checkbox is checked then it should create the contact with the same values given in account such as account name ,phone etc
here is my trigger
trigger accctrg on Account (after insert,after update) {
Account acc = trigger.new[0];
if(recclass.isrecursive = true){
recclass.isrecursive=false;
account ac = new account(id= acc.Id);
if(acc.create_contact__c== true){
Contact con = new Contact();
con.LastName = ac.Name;
con.Phone = ac.Phone;
con.AccountId = acc.Id;
update con;
}
}
}
public with sharing class recclass {
public static Boolean Isrecursive = true;
}
iam not getting any errors but my code is not working
Regards
Raghava
here is my trigger
trigger accctrg on Account (after insert,after update) {
Account acc = trigger.new[0];
if(recclass.isrecursive = true){
recclass.isrecursive=false;
account ac = new account(id= acc.Id);
if(acc.create_contact__c== true){
Contact con = new Contact();
con.LastName = ac.Name;
con.Phone = ac.Phone;
con.AccountId = acc.Id;
update con;
}
}
}
trigger class to avoid recursion
public with sharing class recclass {
public static Boolean Isrecursive = true;
}
iam not getting any errors but my code is not working
Regards
Raghava
update con;
to
insert con;
On another note, while using static booleans to control recursion is a good practice, this trigger is not bulkified and you might want to look inot that as well as this will only work on a single record.