Last active
April 18, 2023 20:22
-
-
Save douglascayers/247f895a1e4324505c65 to your computer and use it in GitHub Desktop.
Example Visualforce Template with iCal Attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<messaging:emailTemplate subject="Close Opportunity" | |
recipientType="User" | |
relatedToType="Opportunity"> | |
<messaging:htmlEmailBody > | |
<html> | |
<body> | |
Opportunity: <a href="https://test.salesforce.com/{!relatedTo.id}"><apex:outputText value="{!relatedTo.name}"/></a> | |
<br/> | |
<!-- | |
Visualforce dateformat trick, put a whitespace character before the date expression and it will format in org's locale, not GMT | |
https://douglascayers.com/2014/05/27/salesforce-displaying-datetime-field-in-visualforce-in-users-timezone/ | |
--> | |
Close Date: <apex:outputText value=" {!relatedTo.CloseDate}"/> | |
<br/> | |
</body> | |
</html> | |
</messaging:htmlEmailBody> | |
<messaging:attachment filename="reminder.ics"> | |
BEGIN:VCALENDAR | |
METHOD:PUBLISH | |
VERSION:2.0 | |
PRODID::-//hacksw/handcal//NONSGML v1.0//EN | |
BEGIN:VEVENT | |
ORGANIZER:mailto:{!recipient.Email} | |
DTSTAMP;TZID=GMT:<apex:outputText value="{0,date,yyyyMMdd'T'HHmmssZ}"><apex:param value="{!relatedTo.CloseDate}"/></apex:outputText> | |
UID:<apex:outputText value="{!relatedTo.id}"/> | |
DTSTART;TZID=GMT:<apex:outputText value="{0,date,yyyyMMdd'T'HHmmssZ}"><apex:param value="{!relatedTo.CloseDate}"/></apex:outputText> | |
DTEND;TZID=GMT:<apex:outputText value="{0,date,yyyyMMdd'T'HHmmssZ}"><apex:param value="{!relatedTo.CloseDate}"/></apex:outputText> | |
SUMMARY:<apex:outputText value="Close Opportunity {!relatedTo.name}"/> | |
DESCRIPTION:<apex:outputText value="{!JSENCODE(relatedTo.description)}" escape="false"/>\n\n<apex:outputText value="https://test.salesforce.com/{!relatedTo.id}" escape="false"/> | |
BEGIN:VALARM | |
TRIGGER:-PT1D | |
ACTION:DISPLAY | |
DESCRIPTION:Reminder | |
END:VALARM | |
END:VEVENT | |
END:VCALENDAR | |
</messaging:attachment> | |
</messaging:emailTemplate> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out my new blog post for a solution that does not require Visualforce or attachments, https://douglascayers.com/2019/06/22/how-to-send-google-and-outlook-calendar-invite-links-in-email-templates/