• #58957

    Trigger to prevent Date Overlap #ApexTrigger

    Hi everyone,

    I am a newbie Salesforce Developer. And I am new to this forum as well :).

    I am trying to write a trigger for a requirement where a new record should not be created if the dates overlap. There are 2 objects Event1 (Campaign renamed) and Attendee. There is a junction object Event Attendee which allows an attendee to register for an Event. If an attendee is already registered for an event then he/she should not be able to register for any other event which falls on those dates or whose start or end dates overlap the already registered event dates. So this trigger that I wrote lets me create records for overlapping dates. If there is one EA record for an Attendee with dates 2/4/2019 and 3/4/19 as start and end dates respectively, there shouldn’t be another EA record for an Attendee with dates overlapping 2/4/2019 and 3/4/2019.

    Please help me fix my logic. Thanks.




    • This topic was modified 4 months, 2 weeks ago by  Suman Humane.
    • This topic was modified 4 months, 2 weeks ago by  Suman Humane.
    Salesforce | Rajan Rajan #23

    Hi Suman,

    Create two map in your trigger to store start and end date corresponding to the register event of that window. So the first map will contain information about start date for each attendee and second map will store end date for each attendee. Now iterate over the event the attendee is trying to register, if the attendee is already in map and either start and end date of the event false between the start and end date from the map then throw the error other wise create a new entry in the start and end date map.

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

Popular Salesforce Blogs


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?