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
Parteek Goyal 3Parteek Goyal 3 

How to create email body in apex class

Hi All,

actully i want to create email body in apex class. i already create it like this:

body='Hello';

But i want to define this body in more than one line.
Please help me.
Best Answer chosen by Parteek Goyal 3
kaustav goswamikaustav goswami
Hi Prateek,

You will have to use the setHtmlBody() method.

Example:

// create an instance of the email message class
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// use the html body to set the content of the body
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created.<p>'+
      'To view your case <a href=https://na1.salesforce.com/'+case.Id+'>click here.</a>');

Thanks,
Kaustav


All Answers

kaustav goswamikaustav goswami
Hi Prateek,

You will have to use the setHtmlBody() method.

Example:

// create an instance of the email message class
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// use the html body to set the content of the body
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created.<p>'+
      'To view your case <a href=https://na1.salesforce.com/'+case.Id+'>click here.</a>');

Thanks,
Kaustav


This was selected as the best answer
@anilbathula@@anilbathula@
Hi Parteek Goyal 3,


check this blow for more info:-
http://www.sfdc99.com/2014/03/01/sending-emails-using-apex/

Thanks
Anil.B
Parteek Goyal 3Parteek Goyal 3
Hi kaustav goswami,

This code is really helpful for me. Thanks for your help.

Thanks,
Parteek Goyal