A service for sending templated emails, with optional ICS (iCalendar) meeting invites attached. Built to be called two ways — synchronously from a Flow, or asynchronously by publishing a platform event.
- Sends every request in a batch through one
Messaging.sendEmailcall, regardless of batch size. - Can attach a calendar (
.ics) file to the email, withREQUEST,CANCEL, orPUBLISHas the method, anATTENDEEline, and an optionalORGANIZERline. - Same send logic runs whether it's called directly from a Flow or through the
Send_Email_Event__eplatform event. - An unresolved template, a recipient without an email address, or a failed send is skipped and logged instead of stopping the rest of the batch.
| Component | Purpose |
|---|---|
SendEmailInvocable |
@InvocableMethod — call directly from a Flow as the Send Templated Email action. |
Send_Email_Event__e |
Platform event — the async boundary. Publish a record to queue a send without holding up the publishing transaction. |
SendEmailEventService |
Maps delivered Send_Email_Event__e records to SendEmailInvocable requests and validates ICS_Method__c, since platform events can't use a Validation Rule. |
SendEmailEvent |
after insert trigger that delivers the platform event to SendEmailEventService. |
ICS Event Emails |
Permission set with the access needed to publish Send_Email_Event__e and invoke the invocable action. |
Trigger a send either by:
- Adding the Send Templated Email invocable action to a Flow, or
- Publishing a
Send_Email_Event__erecord — a Create Records element in a Flow, orEventBus.publish(...)from Apex.
Both accept the same set of fields:
| Field | Invocable Variable | Platform Event Field | Required | Description |
|---|---|---|---|---|
| Email Template API Name | templateName |
Email_Template_API_Name__c |
Yes | Developer name of the EmailTemplate to send. |
| Recipient Contact ID | recipientContactId |
Recipient_ID__c |
Yes | Contact to send to. |
| Recipient Email | recipientEmail |
Recipient_Email__c |
Used for the ICS ATTENDEE line. |
|
| Sender Address | senderAddress |
OrgWideEmailAddress__c |
Org-wide email address; uses the org default when blank. | |
| Related Record ID | whatId |
Related_Record_ID__c |
Record the email relates to, for merge fields and activity logging. | |
| Log Email on Send | logActivity |
Log_Email_on_Send__c |
Logs the email as an activity on send. | |
| ICS Subject | icsSubject |
ICS_Subject__c |
SUMMARY line of the attached calendar event. |
|
| ICS Start Time | icsStartTime |
ICS_Start_Time__c |
Setting this attaches a calendar file to the email. | |
| ICS End Time | icsEndTime |
ICS_End_Time__c |
Defaults to one hour after the start time. | |
| ICS UID Record ID | icsUid |
ICS_UID__c |
Stable identifier for the event; reuse it across sends so reschedules update the same calendar entry. | |
| ICS Method | icsMethod |
ICS_Method__c |
REQUEST (default), CANCEL, or PUBLISH. |
|
| ICS Organizer Email | icsOrganizerEmail |
ICS_Organizer_Email__c |
Adds an ORGANIZER line identifying who scheduled the event. |
|
| ICS Organizer Name | icsOrganizerName |
ICS_Organizer_Name__c |
Display name for the ORGANIZER line. |
To work on this project in a scratch org:
- Set up CumulusCI
- Run
cci flow run dev_org --org devto deploy this project. - Run
cci org browser devto open the org in your browser.