+ Start a Discussion

Sync within 2 objects using triggers



I have 2 objects, one custom object appointments__c and another salesforce's event object.


I want have data from both these objects to be in sync with each other. So i have written 2 triggers one each for each object where in if any appointment is created, a event is created and when event is created then appointment is created.


Issue here is that both the triggers would fire and would get into infinite loop and salesforce throws error.


Any ideas on how to get over this




hi Prady,


Try setting a Static variable and firing the Triggers based on the Static Variable condition like:


 public static boolean AppointmentFlag = true;

public static boolean EventFlag= true;



when a appointment is created then the Event Trigger is fired, check if the Appointment flag = true  and Event flag = False And in the end Set the Appointment flag to false after creating the Event


Similarly when am Event is created  then appointment triger is fired,  check if the Event flag is set to true and Appointment flag is false and later set it to Event Flag False later.


in any case only one flag should be True to fired the code.


Hope this helps.



This is what i was looking for ... But i have a question... Where would i need to create the static variables?


Thanks for the pointer


You can create two sets of classes one for Appointment and other for Event Example:

public class p


public static boolean firstRunAppointment = true;



And check this Static Values while initially calling in the Triggers and set it to False before the end of each Trigger.