Last Updated on November 24, 2020 by Rakesh Gupta
Big Idea or Enduring Question:
There is a formula function called BR() that allows us to insert a line break into text formula expressions or string of text, As shown in the following screenshot:
The expected result in the formula field is:
LastName
FirstName
But you will get the actual result similar to the following line because of the known issue (https://success.salesforce.com/issues_view?id=a1p300000008YkZAAU)
LastName_BR_ENCODED_FirstName_BR_ENCODED_
Objectives:
After reading this blog post, the reader will be able to:
- How to write a formula in process builder to add a line break
Business Use Case
Pamela Kline is working as a System administrator at Universal Containers (UC). She wants to update the Lead’s Description field with Lead’s Last Name in the next line of Lead’s First Name.
Automation Champion Approach (I-do):
Let’s begin building this automation process.
Guided Practice (We-do):
There are 5 steps to solve Pamela’s business requirement using Lightning Flow. We must:
- Creating a custom label to store (-)
- Define process properties
- Define evaluation criteria
- Define process criteria
- Add action – update records
Step 1: Creating a Custom Label
- Click Setup.
- In the User Interface, type Custom Labels.
- Clicks on the New Custom Label button.
- Enter Short Description the Name will auto-populate.
- Now enter the — in the Value.
- Click Save.
Step 2: Define Process Properties
- Click Setup.
- In the Quick Find box, type Process Builder.
- Select Process Builder, then click New.
- Name the Process and click the Tab button. The API Name will populate.
- As a best practice, always input a description.
- The process starts when A record changes.
- Click Save.
Step 3: Define Evaluation Criteria
- Click on the Add Object node to begin selecting the evaluation criteria.
- Select the Lead object from the dropdown list.
- Start the process when a record is created or edited.
- Click Save.
Step 4: Define Process Criteria
- Click the Add Criteria node to begin defining the process criteria.
- Name the criteria.
- The criteria should execute actions when the No Criteria – just execute the actions!.
- Click Save.
Step 5: Add Action – Update Records
- Below Immediate Actions, click Add Action.
- For Action Type, select Update Records.
- Name the action.
- Select the option Select the Lead that started your process record type.
- The criteria for updating records should be No criteria – just update the records!
- Set new field values for the records you update:
- Row 1:
- Field: Description
- Type: Formula
- Value: [Lead].FirstName &
SUBSTITUTE($Label.NewLine, “-“,””)&
[Lead].LastName
- Row 1:
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Don’t forget to active the Process by clicking on the Activate button.
Proof of concept
Now onwards, if a business user updates the Lead, Process Builder will automatically populate the description with First Name and Last Name field.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.
After this was published SF cleared up the encode text error and you can now use BR() again. One thing to note (though perhaps obvious) is that the target field of the update must be a text area field not a regular text field, as the latter doesn’t accommodate 2 lines.
As far Laura’s question, Rich Text fields often don’t behave nice on text updates. I’ve gotten around its issues with creating a duplicate non-rich text field that references it and performing the update on the latter.
Success! i can confirm that this wokrs in screenflows too.
Any idea if this behaves differently when inserting into a Rich-Text field? I have used this solution before and it worked but I just tried to re-use it just now and it’s not working.
Great work! This was helpful
Super workaround, works with flows as well! Thanks a lot!
Thanks, Klaus! I am glad it was helpful 🙂
I know this is likely a silly question, but how would this work if I’m using to create a task and I want the description to have the carriage return?
I’m not quite understanding how the formula would work since I’m not relying on fields, instead plain text. My initial thought would be something along the lines of:
STRING(TEXT(“Text”)) &
SUBSTITUTE($LABEL.NewLine, “-“, “”) &
STRING(TEXT(“More Text”))
But that doesn’t seem to work.
Also tried:
TEXT(“Text”) &
SUBSTITUTE($LABEL.NewLine, “-“, “”) &
TEXT(“More Text”)
and:
“Text” &
SUBSTITUTE($LABEL.NewLine, “-“, “”) &
“More Text”
I’m sure it’s something simple (I hope).
Travis…I was able to use the workaround to add line breaks when creating a task via Process Builder. Here is the formula that I used when setting the content of the Description field.
“Update the following project fields on the portal’s project page for project ” +
[Project2__c].Name + “: ” +
substitute($Label.NewLine,”-“,””) +
if(ISCHANGED([Project2__c].Project_Title__c ) ,”Title”,””) + substitute($Label.NewLine,”-“,””) +
if(ISCHANGED([Project2__c].Abstract__c ) ,”Abstract”,””) + substitute($Label.NewLine,”-“,””) +
if(ISCHANGED([Project2__c].Impacts__c ) ,”Impacts”,””)