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
kcostekcoste 

Visualforce plainTextEmailBody and apex:outputText ignores spacing and line-breaks


Hi, I created a controller, a component, and a plain text Visualforce email template for use in approval processes. Everything works fine except for line breaks in the emails.

 

It had proper line breaks until I added the <apex: outputText/> for formatting numbers and currency.

 

The controller, component and template are as follows:

 

public class MyController { private ID m_opportunityID; . . . public List<Terms__c> getTerms() { List<Terms__c> Terms = new List<Terms__c>(); Terms = [ Select field1__c, field2__c, field3__c From Terms__c Where Opportunity__c = :m_opportunityID ]; return Terms; } }

 

 

<apex:component access="global" controller="MyController" > <apex:attribute name="opportunityID" description="blah" type="ID" required="required" assignTo="{!opportunityID}"/> <apex:repeat value="{!Terms}" var="opp"> <apex:outputText escape="false" value="Display1: {0,number,#,###}, Display2: {1}, Display3: {2,number,currency}"> <apex:param value="{!opp.field1__c}" /> <apex:param value="{!opp.field2__c}" /> <apex:param value="{!opp.field3__c}" /> </apex:outputText> </apex:repeat> </apex:component>

 

 

<messaging:emailTemplate subject="Subject" recipientType="User" relatedToType="Contract"> <messaging:plainTextEmailBody > Please approve blah blah with the following terms: <c:MyComponent opportunityID="{!relatedTo.Opportunity__r.ID}"/> </messaging:plainTextEmailBody> </messaging:emailTemplate>

 

 

But no matter what I try, I get (at best):

 

Please approve the contract with the following terms:
Display1: 1000, Display2: 2009, Display3: $1.00Display1: 2000, Display2: 2010, Display3: $2.00

 

instead of

 

Please approve the contract with the following terms:

 

Display1: 100, Display2: 2009, Display3: $1,001.00
Display1: 200, Display2: 2010, Display3: $2,002.00

 

I've tried placing "\r\n" "%0D%0A", etc, everywhere -- in various formats -- to embed a cariage-return line-feed, both with escape="false" and escape="true" but nothing has any effect.

 

The requirements are plain text -- no HTML email.

 

What am I missing?

Thanks!

kcostekcoste

Tech support provided a workaround. Apparently, it's supposed to work as I posted earlier. The workaround is as simple as placing the first "fixed value" between apex:outputText and the params.

 

For example:

 

<apex:repeat value="{!Terms}" var="opp">
    <apex:outputText escape="false" value=" {0,number,#,###}, Display2: {1}, Display3: {2,number,currency}">
        Display1:
        <apex:param value="{!opp.field1__c}" />
        <apex:param value="{!opp.field2__c}" />
        <apex:param value="{!opp.field3__c}" />
    </apex:outputText>
</apex:repeat>

 

The tech guy said he would report the bug.