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

Email not Receiving After creating EventRelation Record..

Hello ,


 I am looking to add Invitees to an event through apex code , I was succeded to do this using Event Relation Object , but the problem is  I am not able to send any mails like the standard button did..


Can any one plz suggest me how to send an email after creating Event Relation record ..


Thx in advance ..

Jonathan GreenJonathan Green

For others looking, here's how this can be done, where evtId is the event ID and InviteeId is the ID of a user, contact, or lead, by setting the EmailHeader values triggerUserEmail and/or triggerOtherEmail:
EventRelation er = new EventRelation( EventId = evtId, RelationId = InviteeId );
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail  = true; // used if InviteeId is a userId
dlo.EmailHeader.triggerOtherEmail  = true; // used if InviteeId is lead or contact

If you're in a sandbox, make sure emails deliverability is set to All Email to test, or you won't get the emails!

Some helpful documentation here: