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
Rey AustralRey Austral 

How to add outlook calendar event using apex code?

Hi guys

Can you give me a link or code on how to add outlook calendar event using apex, i try to google it but i cannot find any hint. thanks for answering
Best Answer chosen by Rey Austral
Rey AustralRey Austral
Hi Matthews

Thanks for the reply but your code is sending email invite but my problem is, in the created calendar events i want it to add in my outlook calendar by clicking a button add to outlook calendar using apex..

well i have just found out how to do it, you need to use this link /servlet/servlet.OutlookEvent?rnd=1234567890123&id=09A21321
rnd is a random 13 number, and id is the id of the calendar events

All Answers

Gaurav NirwalGaurav Nirwal
// This is for a SINGLE email to all recipients in your list

// From your query results, assembled string that holds the email
// addresses to which you are sending the email.
String[] toAddresses = new String[] {'user@acme.com'}; 
String[] ccAddresses = new String[] {'smith@gmail.com'};

// First, reserve email capacity using size() of query results list
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(queryresults.size());

// Now create a new single email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);

// Specify the address used when the recipients reply to the email. 
mail.setReplyTo('support@acme.com');

// Specify the name used as the display name.
mail.setSenderDisplayName('Event Organizer');

// Specify the subject line for your email address.
mail.setSubject('New Event Created : '+ Event.Name +' '+ Event.Id);

// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);

// Optionally append the email signature to the email.
// If true, email address of user executing Apex Code is used.
mail.setUseSignature(false);

// Specify the text content of the email.
mail.setPlainTextBody('You're invited to a new event: ' + Event.Name + ' ' + Event.Id);

// Optionally, you can specify the HTML template you want to use
mail.setTemplateId(value ForId of Event Template);  

// Specify the HTML content of the email.
mail.setHtmlBody('You\'re invited to a new event:<b> ' + Event.Name + ' ' + Event.Id + ' </b><p> 'To view the details <a href=https://(your salesesforce na1 instance or URI /'+event.Id+'>click here.</a>');

// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Rey AustralRey Austral
Hi Matthews

Thanks for the reply but your code is sending email invite but my problem is, in the created calendar events i want it to add in my outlook calendar by clicking a button add to outlook calendar using apex..

well i have just found out how to do it, you need to use this link /servlet/servlet.OutlookEvent?rnd=1234567890123&id=09A21321
rnd is a random 13 number, and id is the id of the calendar events
This was selected as the best answer
Ashish DeoAshish Deo

Did you find any workaround? I am also facing same issue.

Regards,
Ashish Deo
deo.ashish9999@gmail.com
Gaurav Khare 16Gaurav Khare 16
Hi Rey, Can you post your soluton here..