function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aviator517Aviator517 

Description not populating in .ics attachment

I am working on this code to send an email with an .ics attachment, everything seems to be working ok, except the Description in the .ics attachment is not populating. Could anyone advise on why that might be? Thanks in advance for the help!

 

public class AttendeeConfirmationEmail{
    public static void sendEmail(List<Attendee__c> Attendees) {
List<Attendee__c> attendeelist = [Select ID, Training_Event__r.Start_Date_Time__c, Training_Event__r.End_Date_Time__c, Training_Event__r.Location__c, Contact__r.Email, Contact__r.FirstName, Contact__r.LastName, Training_Event__r.Name, Confirmation_email_sent__c, Training_Event__r.Webinar_Dial_in__c, Training_Event__r.Webinar_Access_Code__c, Training_Event__r.Webinar_Info__c From Attendee__c Where Status__c = 'RSVP - Yes' AND Id in :Attendees];
List<Attendee__c> attendeeupdate = New List<Attendee__c>(); OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'test@email.org']; List<Messaging.SingleEmailMessage> EmailList = New List<Messaging.SingleEmailMessage>(); for(Attendee__c a : attendeelist){ if(a.Confirmation_email_sent__c == False){ DateTime startDate = a.Training_Event__r.Start_Date_Time__c; String formatted_startDate = startDate.format('yyyyMMdd\'T\'Hmm\'00\''); String formatted_startDateII = startDate.format('MMMM d, yyyy \'at\' h:mma'); DateTime endDate = a.Training_Event__r.End_Date_Time__c; String formatted_endDate = endDate.format('yyyyMMdd\'T\'Hmm\'00\''); String dialin = a.Training_Event__r.Webinar_Dial_in__c; String accesscode = a.Training_Event__r.Webinar_Access_Code__c; String location = a.Training_Event__r.Location__c; String body = + 'Thank you for registering for ' + a.Training_Event__r.Name + ' on ' + formatted_startDateII + '. ' + 'The training will be held at ' + a.Training_Event__r.Location__c + '. ' + 'To cancel and/or register for a different training session, please email test@email.org' +(a.Training_Event__r.Webinar_Dial_in__c == Null ? '' : (' \r\n' + ' \r\n' + 'Conference Dial-in Number:' + ' ' + a.Training_Event__r.Webinar_Dial_in__c)) +(a.Training_Event__r.Webinar_Access_Code__c == Null ? '' : (' \r\n' + 'Participant Access Code:' + ' ' + a.Training_Event__r.Webinar_Access_Code__c)) + ' \r\n' + ' \r\n' + 'Best,' + ' \r\n' + 'Training Team'; String subject = a.Training_Event__r.Name + ' confirmation'; String fromAddress = 'test@email.org'; String displayName = a.Contact__r.FirstName + ' ' + a.Contact__r.LastName; String toAddress = a.Contact__r.Email; if(toAddress != null){ String attachmentName = 'Meeting.ics'; Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage(); msg.setOrgWideEmailAddressId(owea.get(0).Id); msg.setToAddresses(new String[] {toAddress}); msg.setSubject(subject); msg.setUseSignature(false); msg.setPlainTextBody(body); Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName(attachmentName ); Blob b = doIcsAttachment(formatted_startDate, formatted_endDate, location, body, subject, fromAddress, displayName, toAddress, dialin, accesscode); efa.setBody(b); msg.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); a.Confirmation_email_sent__c = True; attendeeupdate.add(a); EmailList.add(msg); } } } system.debug('Email list size: ' + EmailList.size()); if(EmailList.size()>0){ Messaging.SendEmailResult[] results = Messaging.sendEmail(EmailList); } if(attendeeupdate.size()>0){ update attendeeupdate; } } private static Blob doIcsAttachment(String formatted_startDate, String formatted_endDate, String location, String body, String subject, String fromAddress, String displayName, String toAddress, String dialin, String accesscode) { // Now Contruct the ICS file String [] icsTemplate = new List<String> {'BEGIN:VCALENDAR', 'PRODID:-//Schedule a Meeting', 'VERSION:2.0', 'METHOD:REQUEST', 'BEGIN:VEVENT', 'DTSTART: ' + formatted_startDate, 'DTSTAMP: '+ String.valueof(DateTime.Now()), 'DTEND: ' + formatted_endDate, 'LOCATION: ' + location, 'UID: ' + String.valueOf(Crypto.getRandomLong()), 'DESCRIPTION: ' + dialin, 'X-ALT-DESC;FMTTYPE=text/html: ', 'SUMMARY: ' + subject, 'ORGANIZER:MAILTO: ' + fromAddress, 'ATTENDEE;CN="' + displayName + '";RSVP=TRUE:mailto: ' + toAddress, 'END:VEVENT', 'END:VCALENDAR' }; String attachment = String.join(icsTemplate, '\n'); return Blob.valueof(attachment); } }

 

Sonam_SFDCSonam_SFDC

I see you have used the same Description Dialin variable in the email template you are sending to the attendee - does that email template show the dialin and access code? or is it not visible in both locations - template and ICS file