I am trying to create an EventRelation record on insert of an Event. Basically I am trying to add WhoID of Event into invitees automatically.
Am I missing anything. I am not getting any error also.
trigger EventTrigger on Event (before insert,after insert, after update, after delete) {
if(!TriggerExecutionController.skipEventTrigger()) {
new EventTriggerHandler().run();
}
public class EventTriggerHandler extends TriggerHandler {
public map<Id, Event> newMap;
public map<Id, Event> oldMap;
public EventRecordSelector evntRecordSelector;
public EventTriggerHandler() {
this.newMap = (map<Id, Event>)Trigger.newMap;
this.oldMap = (map<Id, Event>)Trigger.oldMap;
}
public override void getRecordSelector() {
evntRecordSelector = new EventRecordSelector(Trigger.new, this.oldMap, this);
}
public override void onAfterInsert() {
if (!evntRecordSelector.setEventIds.isEmpty()) {
EventUtilities.addEventAttendee(
evntRecordSelector.setEventIds
);
}
}
}
public class EventRecordSelector implements RecordSelector {
if(eveTriggerHandler.trigType == TriggerHandler.TriggerType.ISAFTER){
if(
eveTriggerHandler.trigEvent == TriggerHandler.TriggerEvent.ISINSERT ||
eveTriggerHandler.trigEvent == TriggerHandler.TriggerEvent.ISUPDATE
){
if(eventRecord.Id != null) {
setEventIds.add(eventRecord.Id);
}
}
}
}
public class EventUtilities {
public static void addEventAttendee (set<Id> setNewEvents) {
system.debug('@@@@@' + setNewEvents);
List<Event> lstEvents = [
SELECT Id,WhatId,WhoId
FROM Event
WHERE Id IN: setNewEvents
];
for(Event e :lstEvents){
EventRelation eR = new EventRelation();
eR.EventId = e.Id;
eR.RelationId = e.WhoId;
system.debug('@@@@@' + eR);
insert eR;
}
}
}
}