2

Starting with Doug Ayers' Visualforce solution (thank you, Doug!) (https://douglascayers.com/2015/01/09/salesforce-send-calendar-invites-in-visualforce-email-templates/), I create the invite as a String and attach it to the email, which seems to be working well for capturing most of the event details, but I would like to include a link in the description, as this particular project is about webinar registrations. The 'DESCRIPTION:' field/node is not a fan of HTML, apparently, and drops everything after the first suggestion of a tag.

Here's the code for the text string:

    public static String createCalendarInvite_EST(String organizerEmail, String slabel, DateTime startDT, DateTime endDT, String summary, String description) {

    String newLine = '\n';
    String result = 'BEGIN:VCALENDAR';
    result += newLine + 'METHOD:PUBLISH';
    result += newLine + 'VERSION:2.0';
    result += newLine + 'PRODID::-//hacksw/handcal//NONSGML v1.0//EN';
    result += newLine + 'BEGIN:VEVENT';
    result += newLine + 'ORGANIZER:mailto:' + organizerEmail;
    result += newLine + 'DTSTAMP;TZID=America/New_York:' + startDt.format('yyyyMMdd') + 'T' + startDt.format('yyyyMMddHHmmssZ').right(11).left(6);
    result += newLine + 'UID:' + slabel;
    result += newLine + 'DTSTART;TZID=America/New_York:' + startDt.format('yyyyMMdd') + 'T' + startDt.format('yyyyMMddHHmmssZ').right(11).left(6);
    result += newLine + 'DTEND;TZID=America/New_York:' + endDT.format('yyyyMMdd') + 'T' + endDT.format('yyyyMMddHHmmssZ').right(11).left(6);
    result += newLine + 'SUMMARY:' + summary;
    result += newLine + 'DESCRIPTION:' +    description;
    result += newLine + 'BEGIN:VALARM';
    result += newLine + 'TRIGGER:-PT1D';
    result += newLine + 'ACTION:DISPLAY';
    result += newLine + 'DESCRIPTION:Reminder';
    result += newLine + 'END:VALARM';
    result += newLine + 'END:VEVENT';
    result += newLine + 'END:VCALENDAR';

    return result;

}

(I've hard-coded the date/time as EST; GMT was resulting in a disconnect between the values as they appeared in the email body and the calendar entry, and I took a hammer to it. I'll revisit that another time ...)

I see where adding the email address after 'ORGANIZER:mailto:' works cleanly; does anyone have experience creating links in a related way?

  • Does anyone have experience with...? is not a question you actually care about the answer to. What you should really ask (and you removed my attempt to fix via edit) is How do I...? – Adrian Larson Jan 7 at 22:57
  • Sorry, Adrian -- didn't mean to overwrite. Makes sense. – Duncan Stewart Jan 8 at 16:11
2

I'd go with the answer to HTML in iCal attachment from StackOverflow.

It is not strictly forbidden by the RFC, but DESCRIPTION is not the appropriate property for HTML content.

DESCRIPTION should be the plain text version of your content. The property X-ALT-DESC with a FMTTYPE declaration of text/html is the appropriate property for HTML content.

Combining that with the C# example from Using X-ALT-DESC / Applying HTML to calendar invites in Outlook gives something like the following in Apex:

result += newLine + 'DESCRIPTION:' +    description;
string html_body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">' +
        '\n<html>' +
        '\n<head>' +
        '\n<title></title>' +
        '\n</head>' +
        '\n<body>';
html_body += '<p>Hello <b>Bold</b> New World</p>';
html_body += '</body>\n</html>';
result += newLine + 'X-ALT-DESC;FMTTYPE=text/html:' + html_body;
result += newLine + 'BEGIN:VALARM';

You might need to experiment with the new line characters a bit.

  • 1
    Thanks, Daniel - I've been working with variations this morning, and as I have gmail I've been looking at how it works there, and neither DESCRIPTION nor X-ALT-DESC are resulting in anything appearing in the Description field of the calendar entry. I'm going to spend time with iCalendar.org (icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html) and see what that yields. – Duncan Stewart Jan 8 at 16:16
  • 1
    Correction: The Description is appearing; the email is being delayed significantly, and I was validating an earlier iteration. The iCalendar validator is proving quite useful, meanwhile. – Duncan Stewart Jan 8 at 16:24

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.