[SalesForce] Event : Workflow Email Alert Template – Add to Calendar Button(s)

Issue: We have a request from our Education department to send our customers an email reminder when we book a new Event with them. We
have a large no-show problem with customers forgetting about their
booked events with us and are hoping to solve some of it by sending
them an email reminder as soon as the event is booked. Inside of this email we would like to embed functionality to automatically add the Event to
their calendar via a simple "Add to Calendar" link. Ideally we'd like to support all Calendars, but at a bare minimum we want to support Outlook, iCalendar, and Google Calendar.

From my research, I've determined that Google Calendar seems easiest – Google supports URL parameters that allow me to just pass in Event specific details using merge fields into the URL which brings up a new window for that event to be saved to the Google Calendar.

Problem: Outlook and iCalendar however are not as simple as Google, apparently. It looks like they both support the .ics file
format (the universal Calendar Event file type), but neither of them
have a URL available that I can pass parameters to. From the research
I've done (Here) and (Here) it appears that the only
approach to handling the creation of these .ics files is to have a PHP
page that serves an .ics file via the text/Calendar mimetype and a
bunch of different data points for the Event – resulting in the php
page serving a downloadable .ics to then be opened in another
application.

Salesforce doesn't support the hosting of PHP files, so this option is not viable if I want to keep everything within the Salesforce platform. I've also tried a website called "AddThisEvent" (suggested in the answer HERE) but it requires that we embed a javascript reference in the <head> of the page which doesn't work with email clients.

Question: So ultimately my question is – can this be done within Email Alerts/Visualforce Pages/Apex without the need for an external
PHP page? Or will I need to have our marketing/web team create a PHP
page that is capable of receiving parameters, interpreting them, and
outputting a correct .ics? I'm looking to solve this problem without
apps, but welcome any and all suggestions.

Best Answer

I solved this with a simple VisualForce page by changing the ContentType attribute of the <apex:page> and by setting the Content-Disposition via a custom controller with ApexPages.currentPage().getHeaders().put('content-disposition','inline; filename=calendarEvent.ics'); in the constructor

<apex:page ContentType="text/Calendar" controller="CalendarInviteController">
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//hacksw/handcal//NONSGML v1.0//EN
    BEGIN:VEVENT
    UID:uid1@example.com
    DTSTAMP:20170426T203000
    ORGANIZER;CN=ABC CO:MAILTO:education@ABCCo.com
    DTSTART:{!startDate}
    DTEND:{!endDate}
    SUMMARY:{!summary}
    STATUS:CONFIRMED
    LOCATION: {!location}
    END:VEVENT
    END:VCALENDAR
</apex:page>

public class CalendarInviteController {

    public String getLocation() {
        return location;
    }


    public String getSummary() {
        return summary;
    }


    public String getEndDate() {
        return endDate;
    }
    public String getStartDate() {
        return startDate;
    }

    private final String startDate;
    private final String endDate;
    private final String summary;
    private final String location;

    public CalendarInviteController(){
        ApexPages.currentPage().getHeaders().put('content-disposition','inline; filename=calendarEvent.ics');

        startDate = ApexPages.currentPage().getParameters().get('startDate');
        endDate = ApexPages.currentPage().getParameters().get('endDate');
        summary = ApexPages.currentPage().getParameters().get('summary');
        location = ApexPages.currentPage().getParameters().get('location');
    }
}
Related Topic