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
anurajanuraj 

Triggers

Hi

   I have a trigger in Event and 1 in Appointment. If any update of delet in any of the object Event or Appointment the trigger will fire and will update or delet. eg : if any record is updated in the Event it also effect the Appointment. same happen with the Appointment. but i cant able to stop it please help me. If it is updated of deleted once then the trigger should not be fireed.

Thanks

Anuraj 

vishal@forcevishal@force

can you post your code if possible?

anurajanuraj

Hi

trigger EventTrigger on Event(after insert, after update)
{
   Set<Id> ev = new Set<Id>();
   List<Event> eventlist = new List<Event>();
   List<Appointment1__c> appoint = new List<Appointment1__c>();
   
  // Event evt = new Event();
    for(Event e:Trigger.new)
    {
      
      ev.add(e.id);
      
    } 
      eventlist = [Select  id, WhoId, IsRecurrence, RecurrenceActivityId, EndDateTime, StartDateTime, Subject from Event where Id in :ev];
      appoint = [Select Client__c , StartDateTime__c , EndDateTime__c , Name , EventID__c from Appointment1__c where Id in :ev];
      System.Debug('+++++++++++++++++++++++++++++++++++++++++++'+ eventlist.size() );
      System.Debug('+++++++++++++++++++++++++++++++++++++++++++'+ eventlist);
     // System.Debug('+++++++++++++++++++++++++++++++++++++++++++'+ evt.ID);
      if( Trigger.isInsert)
      {
       for(integer i=0; i<eventlist.size(); i++)
       {
         Appointment1__c a = new Appointment1__c();
         if(eventlist[i].IsRecurrence == true)
         {
             
             a.Client__c = eventlist[i].WhoId;
             a.StartDateTime__c = eventlist[i].StartDateTime;
             a.EndDateTime__c = eventlist[i].EndDateTime;
             a.Name = eventlist[i].Subject;
             a.EventID__c = eventlist[i].ID;
             appoint.add(a);
           
         }     
         else
         {
             a.Client__c = eventlist[i].WhoId;
             a.StartDateTime__c = eventlist[i].StartDateTime;
             a.EndDateTime__c = eventlist[i].EndDateTime;
             a.Name = eventlist[i].Subject;
             a.EventID__c = eventlist[i].ID;
             appoint.add(a);
           
          }
         } 
           insert appoint;
      }
     
       if(Trigger.isUpdate)
      {
         for(integer i=0; i<eventlist.size(); i++)
          {
          for(integer j=0; j<appoint.size(); j++)
          { 
           if(eventlist[i].Id == appoint[j].EventID__c)
            {
                 appoint[j].Client__c = eventlist[i].WhoId;
                 appoint[j].StartDateTime__c = eventlist[i].StartDateTime;
                 appoint[j].EndDateTime__c = eventlist[i].EndDateTime;
                 appoint[j].Name = eventlist[i].Subject;
                 //appoint.add(appoint);
                 update appoint;
                 System.Debug('++++++++++++++++++++++++++++++'+appoint);
            }
          }
         } 
         // upsert appoint;

      }
      
      }

 This is the trigger written in Event and same is the code for Appointment.

thanks

Anuraj