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
rajjjjrajjjj 

Splitting Text area field into multiple lines

How can we split an address field(text area) into multiple lines. It shows in multiple lines. But when used in template will show all in one line.

 

Lets consider Billing Street. I am building a rich text area field where I need to display that field in a template. Now it is showing Billing Street in one line. I need to show them into mulitple lines.

 

I was using

String s = billingstreet.replaceAll('\r\n','<br/>');

String s = billingstreet.replaceAll('\n','<br/>');

 

Eg: 123 broad street <br/> headquarters of office

Even when i try this in rich text area its not displaying in seperate lines. Showing as same.

 

But nothing is working. Any Ideas!!!

Best Answer chosen by Admin (Salesforce Developers) 
rajjjjrajjjj

I got it resolved... Text area can contain  \n. If you press enter on address and again give a backspace when multiple lines are there. It changes from \n to '\r\n'

So u need to make sure u replaceall of \r\n with \n and then do a split and add <br/>.

That way <br/> gets appended to multiple lines and richtext area field will recognise <br/> and split into multiple lines.

All Answers

AsitM9AsitM9
<apex:outputText escape="true">{!bindSomeVaricble} </apex:outputText>

 try this one.

sambasamba

checked your email template type, i think it's a Text, it's not html.

rajjjjrajjjj
@asitM9...That is when we are using visualforce. I am building my template in Apex.
@samba... No its a html email template only.
rajjjjrajjjj

I got it resolved... Text area can contain  \n. If you press enter on address and again give a backspace when multiple lines are there. It changes from \n to '\r\n'

So u need to make sure u replaceall of \r\n with \n and then do a split and add <br/>.

That way <br/> gets appended to multiple lines and richtext area field will recognise <br/> and split into multiple lines.

This was selected as the best answer
Shweta GargShweta Garg
Hi rajj,

I am also stuck in same Porblem.I have created a visualforce email template.I need to show T_Last_External_Post__c (field in  Case object) on email template.

Here is my code.
<messaging:emailTemplate subject="test" recipientType="Contact" relatedToType="Case">
    <messaging:htmlEmailBody >
    
        <html>
            <body>
                 <apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(JSENCODE(relatedTo.T_Last_External_Post__c), '\r\n', '\n'),'\n','<br/>')}" style="white-space:pre;"  />
                         
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

but it not working .
any help is much appreciated.