function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Venkata Ravi Chandra MaddaliVenkata Ravi Chandra Maddali 

Adding Event Invitees through Apex Code

Hi everyone,
I have a tricky situation. I am able to add  contacts as event invitees through apex code but an email is not being sent . On the Event record, the contact names are being populated in the " Has'nt Responded " section of the related list. Only if the contact accepts the invitation, his name would come up in the " Accepted " section of the related list . Untill and unless contact gets an email, he/she cannot accept the invitation.

Any help is appreciated. Thanks in advance.
Rahul BorgaonkarRahul Borgaonkar
Please post more details. Could you share you code where email is sent to invitees please?

Jayson Faderanga 14Jayson Faderanga 14
hi Venkata,

try to create a trigger using this code.. hope this helps.. this code also fixes the problem of sending the email notification to your invitees, so they can accept the events..

trigger autoAddInvitees on Event (after insert) {

//bulkify incomingEvents
List<Event> nEvent =;
List<EventRelation> iErelation = new List<Eventrelation>();

//send update to invitees
Database.DMLOptions dmo = new Database.DMLOptions(); 
dmo.EmailHeader.triggerUserEmail = true; 

//loop on bulkfiedEvent
for(Event lEvent : nEvent){
    if(lEvent.IsGroupEvent == false){
 EventRelation er = new EventRelation();
    er.EventId = lEvent.Id;
    er.RelationId = '00528000000q1QV';

Database.insert(iErelation, dmo);


hope that helps.. that fixes the problem of sending an alert to all your invitees
Karthikeyan MBKarthikeyan MB
some more input,
When an event is created, the event relation records are created automatically. The IsInvitee field on the event relation object is set to False during the event relation record creation. This needs to be set as True for the parties (in event relation record) to be considered as invitees. This will ensure the IsGroupEvent field on the corresponding event record to be set as True. This ensures that the event is categorized as multi-party event (an indicator in the UI).
You need to fetch the event relation records (for the corresponding event) and the IsInvitee field needs to be set to True. If we use Database.insert with the DML option, still the email are not getting triggered (i believe its a bug).
Alternate option is to delete the event relation records and insert them using the Database.insert and DML option. The invite email gets triggered only on using Database.insert.