You need to sign in to do that
Don't have an account?
Event object duplicate trigger
Hello Guys,
I am trying to create a trigger to prevent the duplicate meeting request between the start and end date time.
Triggers work when start and end date time matches. However, they do not work between the date time.
I would appreciate if someone could review the code and highlight the issue.
Thanks
I am trying to create a trigger to prevent the duplicate meeting request between the start and end date time.
Triggers work when start and end date time matches. However, they do not work between the date time.
I would appreciate if someone could review the code and highlight the issue.
trigger trg_EventDuplicateBooking on Event (before insert) { if(trigger.isInsert && trigger.isBefore){ cls_DuplicateBooking_handler.checkeventduplicaterecord(trigger.new); } }
public class cls_DuplicateBooking_handler { public static void checkeventduplicaterecord(List<Event> evtList){ try{ set<string> userSet = new set<string>(); set<datetime> eventstartdate = new set<datetime>(); set<datetime> eventenddate = new set<datetime>(); for(Event evt:evtList){ userSet.add(evt.OwnerId); eventstartdate.add(evt.StartDatetime); eventenddate.add(evt.EndDateTime); } List<Event> eventList = [SELECT OwnerId FROM event WHERE OwnerId IN:userSet AND (StartDatetime <=:eventstartdate AND EndDateTime >=:eventenddate)]; If(eventList.size()>0){ evtList[0].addError('User already booked'); } } catch(exception ex){ throw ex; } } }
Thanks
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Thanks for your immediate help.
Unfortunately, it won't work as expected. After i amend something on your code, it triggers for the same start and end date time with for the person. But, it won't work between the datetime.
Can you tweak something please