0

I have a long text area field (Customer_Issues__c) which I'm trying to send using the Apex SendEmail method. The field displays properly in Salesforce with line breaks and paragraphs. When I try to send it as the body of an email, the paragraphs and line breaks aren't displaying properly. When I try to pull the data using workbench, I don't see any html formatting. What am I doing wrong?

string issues = a.Customer_Issues__c;
body = issues;

EmailManager em = new EmailManager();
em.sendMail(adresses, 'TEST Automated Alert: Updated Code Red Account- ' + a.Name, body);

Send Email

  public void sendMail(String address, String subject, String body) {
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

    String[] toAddresses = new String[]{};
        for(String emailId:address.split(',')){
            if(emailId != null && emailId !=''&& emailId != ' '){
                toAddresses.add(emailId.trim());
            }
        }

    mail.setToAddresses(toAddresses);
    mail.setSubject(subject);
    mail.setHtmlBody(body);

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

I don't think it matters but I'm calling the SendEmail from a trigger.

1 Answer 1

2

Since you are setting the HTMLBody, have you tried the following?

body = issues.replaceAll('\r?\n', '<br/>');
1
  • Your solution worked perfectly. Thanks Commented May 27, 2020 at 5:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .