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
James McGillJames McGill 

Add a carriage return/line break to a custom formula

I have a text formula to which I would like to add a carriage return/line break.  I tried concatenating chr(13) and chr(10), but the validation didn't like it.  Is this possible?
Best Answer chosen by Admin (Salesforce Developers) 
EricBEricB
There is a new formula function called BR() in the Winter '07 release.  This will allow you to insert an HTML line break tag into text formula expressions.

For example (using made-up field names):
Code:
Address1 & BR() & 
Address2 & BR() &
City & ", " & State & " " & PostalCode & BR() &
Country

 


Cheers,
Eric Bezar
salesforce.com Product Management

All Answers

KMLKML
I asked Salesforce Support the same question in June as was told "this feature is not available".

They did, however, promise to submit it as a feature request to the development team.
EricBEricB
There is a new formula function called BR() in the Winter '07 release.  This will allow you to insert an HTML line break tag into text formula expressions.

For example (using made-up field names):
Code:
Address1 & BR() & 
Address2 & BR() &
City & ", " & State & " " & PostalCode & BR() &
Country

 


Cheers,
Eric Bezar
salesforce.com Product Management
This was selected as the best answer
James McGillJames McGill
Looks good!  I assume that this will work with text formulas for a Mail Merge?
 
What I am trying to do is have users check boxes that indicate the capabilities we offer, based on the boxes checked, a capability description is created.  I would like a carriage return between each so that when they are shown in the Word document they are each on their own line.  Will the BR() let me do this?
 
Also, when will the 07 be released?
Phil_RPhil_R
The BR() tag works on formulae in salesforce, however when inserting a multi-row formula to a visualforce page (rendering as pdf) returns a result on one line rather than keeping the line breaks.

Both \n and br() don't seem to work.
Does anyone have any other suggestions?
Thanks,
Phil
beenerbeener
And while were at it, does anyone know how to create a page break (new page) when a Visualforce page is rendered as PDF?

Thanks
JeremyKraybillJeremyKraybill
Just in case you didn't find this anywhere else, I was looking for the same thing and found it in a post here.

<div style="page-break-after: always;">&nbsp;</div>

will do it.

HTH

Jeremy
boihueboihue

I think that the "\n" will work for the Carriage Return case:

sReason = 'Retired'; 

newRec.Description__C = '*** Reason for Archiving ***';

newRec.Description__c += '\n\n' + sReason;

etoeto

Phil_R wrote:
The BR() tag works on formulae in salesforce, however when inserting a multi-row formula to a visualforce page (rendering as pdf) returns a result on one line rather than keeping the line breaks.

Both \n and br() don't seem to work.
Does anyone have any other suggestions?


 

BR() also works for PDF generation if you're using apex:outputText with escape=false in your PDF:

 

 

 

 

<apex:outputText escape="false" value="{!yourfield}>
Message Edited by eto on 06-12-2009 05:39 AM
fifedog15fifedog15

I know this is an old thread but I'm unable to get this to work in a field update workflow rule.

 

There is what I have in my workflow rule update:

 

"1.0 This Order .... by both parties." & BR() & 
"2.0 Standard.... the Special Terms section."

However this is what the output is on screen:
1.0 This Order .... by both parties. 2.0 Standard .... the Special Terms section.

 

 

RiflemanRifleman

Did you ever get this to work?  I'm having the same issue.

KevinBrKevinBr

Visual Workflows (not apex/visual page) seem to be different as well..

 

I'm trying to assign a variable to Case Description and a constant variable CR set to \r\n

 

ie

{!varCaseDescription} equals  Steps{!CR}Line2{!CR}Line2{!CR}Line3

 

The \r\n gets to the description field as literals and not converted to their cr/lf codes.

I noticed that html tags also get stripped out. (ie, <p> or <br>)

 

Is there a way to do this?

 

 

BingBing

There is an existing function BR(), which is to add line break in text formula

 

For example:

Contact__r.FirstName & " " & Contact__r.LastName & BR() 
&Contact__r.MailingStreet &BR() 
&Contact__r.MailingPostalCode& " "& Contact__r.MailingCity & BR() 
& Contact__r.MailingState & BR() 
& Contact__r.MailingCountry

 

This returns

John Doe

Hauptstrasse 1234

88888 Munich

Bayern 

Germany

 

Bing Maletz

BingBing

I just noticed that function BR() only works with data type "Text Area" and "Text Area (Long)".  It doesn't work with "Text Area (Rich)".

 

Bing Maletz

docbilldocbill
BR() litterally only works when you want HTML formatting.  If for example your formula field is being returned by an api call, this is probably not what you want...   One way that does allow you to insert a new line or any other special characters is to use labels.   For example, I have a label called NewLine.   The text of the label is litterally:

<
>

From within a formula field I can reference this like:

TRIM(Address_Line1__c+MID($Label.NewLine,1,1)
+Address_Line2__c+MID($Label.NewLine,1,1)
+Address_Line3__c+MID($Label.NewLine,1,1)
+Address_Line4__c)

Note, the label needs to have the dummy starting end ending characters, because all leading and trailing whitespace will be removed.


 
Steve Cox 9Steve Cox 9
For info, using the bounding < and > characters also works when constructing text withing visual flow formulae. However, rather than using a label, you need to create the item by using the 'Text Templates' resource and referring to it in the formula contruction. If the text teplate is called bounded_newline and consists of:

<
>

then

MID({!bounded_newline},2,1)

will produce a newline character
Brian Oconnell 23Brian Oconnell 23
In a visual flow formula field which populates a custom field of type Long Text Area(32768), I cannot add a line break.
I've tried BR(), \n\r, <br/>, Text Templates, etc.

So frustrating that this should be the most difficult part of a very complex Flow.
Patrick Maxwell 2Patrick Maxwell 2
@brian, try this hack out, it worked for me https://automationchampion.com/2015/08/06/getting-started-with-process-builder-part-40-adding-a-line-break-in-process-builder-formula/#comment-3963
Kendra Von AchenKendra Von Achen
Thanks Patrick Maxwell 2, that was a great trick! It's not working as expected in my current Process Builder, but i think it got me a step closer!
MoggyMoggy
I just tried all the most common mentioned in the post, I got my text field as it should be with
'sometext ' & a variable & '<br/>' & sometext

sometext abc
sometext

BR() didn't worked so as '\n' the <br/> worked if you put it in single quotas
John Ondusko 2John Ondusko 2
I am uploading using a field from MS-SQL and used chr(10) (outside of quotes) - seems to work a treat.
Mee SharmaMee Sharma
I know i am picking a very old thread. But guys plz help me put on this.i am facing a similiar issue

I have a flow that populates the content of a ContentNote record. i use a formula that combines values from various variables in the flow and concatenate it.This concatenated text is displayed in the body of the contentNote record.
I am facing issues in adding linebreaks between the two concatenated formulas.I have tried everything BR(),
, /n,/r,
,Substitute((text),"~","").Nothing seems to work.Plz help!

User-added imageUser-added image
Patrick Maxwell 2Patrick Maxwell 2
Hi @Meenakshi, I know how annoying this is, so I'll attempt to answer this for you, but recommend that you review the link I provided above for help.  I don't know what value is in the variable {!NewLinetext} in your screenshot above, but it were this value, it should work (quotes not required.)

"~

~"

I don't know if this "trick" will work if that variable is a flow variable.  The way I do this is using a custom label (Setup->Create->Custom Label) and passing that variable/reference in my SUBSTITUTE formula.

Good Luck!
Rich Finn 2Rich Finn 2
Here is how you can incorporate a carriage return in a message that you want to send in an email within a Process Flow.

1.    Create a custom label (Setup/Create/Custom Labels) – I called mine MedPro_Line_Feed.  The value is a carriage return surrounded by pipes (i.e., “|”).  See Figure 1.  

2.    Then you want to create a formula field in your Flow where you concatenate the MedPro_Line_Feed in your message – please note that the pipes “|” are substituted out of the message so you are left with just the carriage return.  

3.    Add the formula field as the body of the email to be sent.  I used simple email where you identify subject, body, Email addresses.

Figure 1: Create new Custom Label
 Custom Label Detail 
             Short Description    MedPro Line FeedName                  
                         Language   English  

                         Value |
                                   |

Figure 2: Create a formula field as text with the following:
"Please review the Contact information listed below to see if a duplicate record exists.” & SUBSTITUTE($Label.MedPro_Line_Feed, "|", "") & SUBSTITUTE($Label.MedPro_Line_Feed, "|", "") & "Contact Name / ID : " &  {!v_Name_Formula} &" / " & {!v_CONTACTID_Found} &SUBSTITUTE( 
$Label.MedPro_Line_Feed , "|", "") & SUBSTITUTE( $Label.MedPro_Line_Feed , "|", "") 
&"                     Email : " & {!v_Contact_Email}  & SUBSTITUTE( $Label.MedPro_Line_Feed , "|", "")&SUBSTITUTE( $Label.MedPro_Line_Feed , "|", "") & " Thank you."
Asi Avrahami 9Asi Avrahami 9
BR() in long text field
'<br>' in rich text field
Rabbani Basha 1Rabbani Basha 1
try this below
it's working fine.

'Hi'+'<br><br><br><br>'+'Thank you for contacting us.'
Kristi WardKristi Ward
None of the BR(),'BR()', '<br>', '<br />' work in the Process Builder, using a long text field.  After 13 years, why hasn't Salesforce fixed this?
Sean Dukes 24Sean Dukes 24
Based on great work by Gorav Seth, https://goravseth.com/manipulating-text-in-flows.
  1. Create a resource of type text template.
  2. Change your text template to plain text using the drop down and type in <br/>.
  3. Save it with a name - in this example ttLineBreak.
  4. Now use that in your formula {![MyValueIWantToAddALineBreakTo]} & {!ttLineBreak}
Anmol CheemaAnmol Cheema

This Youtube video seems to solve the issue using a combination of constants (using {!$GlobalConstant.EmptyString}) and formulas 

It worked for me - I wanted to concatenate 2 address lines stored as single text fields and have them as 2 lines in the Street address field (long text format).

https://www.youtube.com/watch?v=afUc85_Af9o