How to insert line break in email message using Apex in Salesforce?

To insert line break in email message using Apex in Salesforce, we have to use <br> tag. setHtmlBody() method is used here to send the email in HTML format.

Sample Trigger:

trigger memberInviteNotify on Member__c (after insert,after update)
    for(Member__c member:trigger.New)
        String[] toAddresses = new String[] {member.E_Mail_Id__c};
        String messageBody;
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        //Email invitation
            mail.setSubject('Welcome to Sweet 16 Siebel Batch');
            messageBody = '<html><body>Hi ' + member.Name + ',Welcome to Sweet 16</body></html>';
        //Email notification
            mail.setSubject('Updates in your details');

            //Message with line break tag
            messageBody = '<html><body>Hi ' + member.Name + ',Changes have been made to your details. <br><br>Contact administrator if you are not responisble.</body></html>';

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit