Hi All,
Some times we have a situation where trigger on a event of one object fires another trigger and logic in that trigger again fires first trigger. These situations are called cyclic triggers.
Ex :
In Above example event in Trigger1 invokes Trigger2 and event in Trigger2 again invokes Trigger1.
Solution : If we use entry criteria as explained in earlier post then cyclic trigger problem will be solved.
Writing Apex Trigger : Issues and Solutions ( Entry Criteria)
Some times we have a situation where trigger on a event of one object fires another trigger and logic in that trigger again fires first trigger. These situations are called cyclic triggers.
Ex :
trigger Trigger1 on Account (after update)
{
for(Account acc : Trigger.New)
{
//Trigger Action Logic
List<Contact> listCon = [Select Fax from Contact where AccountId =: acc.id];
for(Contact con : listCon)
{
con.Fax = acc.Fax;
}
update listCon;
}
}Another trigger on Contact object update is written like : trigger Trigger2 on Contact (after update)
{
for(Contact con : Trigger.New)
{
//Trigger Action Logic
List<Account> accList = [Select Phone from Account where id =: con.AccountId];
for(Account acc : accList)
{
acc.Phone = con.Phone;
}
update accList;
}
}In Above example event in Trigger1 invokes Trigger2 and event in Trigger2 again invokes Trigger1.
Solution : If we use entry criteria as explained in earlier post then cyclic trigger problem will be solved.
Writing Apex Trigger : Issues and Solutions ( Entry Criteria)