You need to sign in to do that
Don't have an account?
CosminC
Apex Insert Event invitees before trigger action
Hello,
I have an After Insert trigger on Event which uses data from the related EventRelation objects to get the list of invitees and further create an event in Google Calendar.
I am trying to write a test class for this, inserting an event with invitees, however if I first insert the Event and then I insert EventRelation records to create the invitees, my trigger already fires on the Event insertion which will have no invitees at that point. Is there a way to insert the Event directly with invitees? (I can't seem to find a List of WhoId records on the Event object that would be available through Apex on Event insertion).
Thanks in advance
I have an After Insert trigger on Event which uses data from the related EventRelation objects to get the list of invitees and further create an event in Google Calendar.
I am trying to write a test class for this, inserting an event with invitees, however if I first insert the Event and then I insert EventRelation records to create the invitees, my trigger already fires on the Event insertion which will have no invitees at that point. Is there a way to insert the Event directly with invitees? (I can't seem to find a List of WhoId records on the Event object that would be available through Apex on Event insertion).
// setup test data Account a = new Account(); a.Name = 'Test account'; insert a; List<Contact> contacts = new List<Contact> {new Contact(LastName = 'Test Con1', Email = 'test@test.ro'), new Contact(LastName = 'Test con2', Email = 'test@test.com')}; insert contacts; Event e = new Event(); e.Description = 'Test event description'; e.Subject = 'Test event subject'; e.IsAllDayEvent = false; e.IsRecurrence = false; e.StartDateTime = DateTime.now(); e.EndDateTime = DateTime.now().addHours(1); insert e; // trigger will already fire here, before EventRelation records are inserted. EventRelation er1 = new EventRelation(); er1.EventId = e.Id; er1.IsInvitee = true; er1.IsWhat = false; er1.RelationId = contacts.get(0).Id; EventRelation er2 = new EventRelation(); er2.EventId = e.Id; er2.IsInvitee = true; er2.IsWhat = false; er2.RelationId = contacts.get(1).Id; List<EventRelation> ers = new List<EventRelation>{er1, er2}; insert ers;
Thanks in advance
I hope it will solve your problem.
Thanks,
Nitish