+ Start a Discussion
Siarhei balantsevichSiarhei balantsevich 

Help. I need rewrite this trigger for many new objects. Not for 1

trigger checktime on Appointment__c (before insert, before update) {
    Time startDate;
    Datetime endDate;
    String Name;
       List<Appointment__c> events = [
           SELECT Id FROM Appointment__c 
           WHERE Appointment_Data__c <= :TRIGGER.new[0].Appointment_Data_End__c 
           and Appointment_Data_End__c>=:  TRIGGER.new[0].Appointment_Data__c 
           and Doctor__c =:TRIGGER.new[0].Doctor__c
           Trigger.new[0].addError('Error GMAK');
mukesh guptamukesh gupta
Hi Siarhei,

you need to write again for each object , you can't use same objet trigger for multiple object operations.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.


Andrew GAndrew G
Hi Siarhei

Mukesh is correct, each object will need its own trigger. 

Perhaps the only way to shorten the process would be to create a Trigger Handler class that utilises the sObject class and then invoke that class in each of the triggers that you create.

Suraj Tripathi 47Suraj Tripathi 47
Hi Siarhei balantsevich,

"One trigger Per sObject" it means developer can never use one trigger code (which was written for another sObject) for other sObject. When we are creating a trigger, it takes the name of the trigger and the Name
of sObject. We can create many triggers for one sObject but one trigger does not work for another sObjects.

If you find your Solution then mark this as the best answer. 

Thank you!

Suraj Tripathi
Satish InugantiSatish Inuganti
Hi Siarhei,

If the logic is same I would suggest a to create a common handler class and call the method from each object trigger instead of writing it in the trigger that would atleast help to solve the redundancy in the code. But if the action needs to be done many objects as mentioned above on each object a trigger is needed.

Thank you,
Satish Inuganti.
mukesh guptamukesh gupta
Hi Siarhei,

if you agree with my suggesation so please 

Kindly mark my solution as the best answer if it helps you.