RSS

Saving Line Breaks to Text Fields

01 Dec
Saving Line Breaks to Text Fields

Here is a quick little tip on how to save two strings, with a line break between them, to a text area field when you’re in Visual Flow.


Using BR() Doesn’t Work

Salesforce text formula fields allow the use of a BR() function to force a line feed in the value of the field.

For instance, if I have a formula field of “Line 1” & BR() & “Line 2” the output will be:

Line break formula field output

Result of BR()

.

Visual Flow uses most of the same functions that are available in formula fields so it would make sense that BR() could be used in a flow formula. And, indeed, if BR() is used in a formula the Flow will save just fine.

Unfortunately, though, you will not get the result you want:

BR_ENCODED Result

BR_ENCODED Result


The Workaround

The workaround requires that you take one extra step, and use a different function.

The Extra Step

The extra step is to create a Text Template as follows:

  1. Enter a text character or string (in this example I’m using “~”)
  2. Tap the Enter key to go to the next line
  3. Enter the same character or string
Line Break Text Template

Line Break Text Template

.

The Alternate Function

The function you’ll use instead of BR() is SUBSTITUTE(). The syntax of SUBSTITUTE is:

SUBSTITUTE( WorkingString, StringToLocate, SubstitueString )

  • The WorkingString is the string that the Substitute function is working on
  • The StringToLocate is what you’re looking for in the WorkingString
  • The SubstituteString is the value that will be place into the WorkingString in lieu of the StringToLocate

So in my example this would look like:

  • SUBSTITUTE(TextTemplate, “~”, “”)

The Final Formula

So your final formula will be:

String1 & SUBSTITUTE( TextTemplate, SearchString, “”) & String2

Line Break Formula

Line Break Formula


Using the Line Break Formula

You can now use your formula to populate Text Area fields that allow for separate lines. You can also use your formula to display text in display fields in your flow screens.


Taking it One Step Further – Just For Fun

Let’s take it one step further and add a line between strings. For example, let’s say you have a description field that you’re adding information to, but you want to see a visual break between the old and new text.

Description Field with Visual Break Between Comments

Description Field with Visual Break Between Comments

.

Super simple to do! Just add anything to your text template that you want to be added to the final value of your formula:

Text Template with Line

Text Template with Line


Resources:

Advertisements
 
Leave a comment

Posted by on December 1, 2015 in Flow Tips & Tricks, Formulas, Visual Flow

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: