1

I am trying to build a button to be included in an email that goes to a public page to generate an ICS file. We also have in the email a visualforce attachment but this does not work with mobile outlook(attachment is just completely not there) and ios, therefore the button is a fail safe for the client to click. The below only works with desktop outlook and doesn't work with any mobile app.

The main difference between the visualforce page and the message:attachment in the email is that I can't get breaklines to work and suspect this is what is causing the visualforce page generated ics to not work on mobile. I have tried every forum thread suggestions of using different things like \n,
etc for line breaks but when you download the file it will just display the entire file in one line (and include '\n' or '
).

Page:

    <apex:page standardController="Event" ContentType="text/calendar">
BEGIN:VCALENDAR
PRODID:-//GourmetPortal//NONSGML rr//DE
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(Event.StartDateTime),':',''),'-',''),' ','T')}"/>
DTEND;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(Event.EndDateTime),':',''),'-',''),' ','T')}"/>
DTSTAMP;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
ORGANIZER;CN=test@futureassist.com.au:mailto:test@futureassist.com.au
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;X-NUM-GUESTS=0:mailto:<apex:outputtext value="{!Event.Client_Email__c}"/>
UID:<apex:outputText value="{!Event.id}"/>
CREATED;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
DESCRIPTION:<apex:outputText value="Please contact your adviser if you need to reschedule the time of this appointment" escape="false"/>
LAST-MODIFIED;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:<apex:outputText value="{!Event.Subject}"/>
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:This is an event reminder
TRIGGER:-P0DT0H30M0S
END:VALARM
END:VEVENT
END:VCALENDAR
</apex:page>

Extension:

public with sharing class GenerateEventICS {

    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 GenerateEventICS(ApexPages.StandardController controller){
        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');
    }
}

Message attachment for reference (it's the same things but break line works):

 <messaging:attachment filename="{!relatedTo.Subject}.ics" renderAs="text/calendar">
BEGIN:VCALENDAR
PRODID:-//GourmetPortal//NONSGML rr//DE
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(relatedTo.StartDateTime),':',''),'-',''),' ','T')}"/>
DTEND;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(relatedTo.EndDateTime),':',''),'-',''),' ','T')}"/>
DTSTAMP;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
ORGANIZER;CN=test@futureassist.com.au:mailto:test@futureassist.com.au
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;X-NUM-GUESTS=0:mailto:<apex:outputtext value="{!relatedto.Client_Email__c}"/>
UID:<apex:outputText value="{!relatedTo.id}"/>
CREATED;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
DESCRIPTION:<apex:outputText value="Please contact your adviser if you need to reschedule the time of this appointment" escape="false"/>
LAST-MODIFIED;TZID=GMT:<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ','T')}"/>
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:<apex:outputText value="{!relatedTo.Subject}"/>
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:This is an event reminder
TRIGGER:-P0DT0H30M0S
END:VALARM
END:VEVENT
END:VCALENDAR
</messaging:attachment>

Opening the visualforce page generated ics in notepad: Opening the message:attachment generated ics in notepad: enter image description here

3
  • since it's visualforce, can you try using standard HTML linebreaks? Just add <br/> at the end of each line, see if it works – Novarg Sep 13 '17 at 9:30
  • Already tried this, it works without using any contenttype but when you add the text/calendar it just ends up as <br/> in the single line of text eg: BEGIN:VCALENDAR<br/>PRODID:-//GourmetPortal//NONSGML rr//DE – Michael Sep 13 '17 at 9:48
  • then I suppose you also tried \r\n? – Novarg Sep 13 '17 at 12:49
1

I fixed the issue with the breakline by updating the content type from

ContentType="text/calendar"

to

ContentType="text/calendar;charset=utf-8"

I noticed in notepad ++ the breaklines were appearing and then found out the encoding was different and needed to be specified. The file is still not working on mobile but I will post a different question for that if it comes to it. the only difference between the 2 now is the contenttype vs renderas (works in android gmail).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.