You need to sign in to do that
Don't have an account?
Jonathan Osgood 3
Dusting off Apex Chops
Hi All,
Sadly I havent been writing apex for a long time and could use some help. I'm repurposing some code I have to compare two records and throw an error if there is a match on date. This is a before trigger that calls the below helper class . I'm getting a null pointer error on line 30 when I try to get the date from my Map which leads me to beleive I'm not populating my map correctly. Any help would be greatly appreciated.
Sadly I havent been writing apex for a long time and could use some help. I'm repurposing some code I have to compare two records and throw an error if there is a match on date. This is a before trigger that calls the below helper class . I'm getting a null pointer error on line 30 when I try to get the date from my Map which leads me to beleive I'm not populating my map correctly. Any help would be greatly appreciated.
public class EventTriggerHelper { public static void CheckForDoubleBookedLocations(List<Event__c> locEvts){ //collect ID's to reduce data calls List<ID> locationIds = new List<ID>(); Map<ID,Event__c> requestedEventTime = new map<ID,Event__c>(); //get all Locations related to the trigger for(Event__c newEvent : locEvts){ if(newEvent.Event_Location__c != null){ locationIds.add(newEvent.Event_Location__c); } //Populate Map List<Event__c> relatedEvents = [SELECT Event_Location__c, Start_Date_Time__c FROM Event__c WHERE Event_Location__c IN :locationIds]; for(Event__c relatedEvent : relatedEvents){ requestedEventTime.put(relatedEvent.Id, relatedEvent); //get existing events to check against list<Event__c> existingEvents = [SELECT ID, Event_Location__c, Start_Date_Time__c FROM Event__c WHERE Event_Location__c IN :locationIDs]; //check one list against the other for(Event__c evs : locEvts){ DateTime existStartTime = requestedEventTime.get(evs.Id).Start_Date_Time__c; for(Event__c event : existingEvents){ ////Add location and end date range Logic if(event.Start_Date_Time__c == existStartTime){ event.addError('The Location is already booked at that time'); } } } } } } }
Please try below code..
Please let me know if this help !
Thanks
Shivdeep