3rd Oct 2018

Returning Multiple Values from a Long Text Field in a Flow in Salesforce

by: Fan Yang

blog hero img

Business Case

Let’s say you wanted to gather feedback from all 150 of your Salesforce Users about what your new company mascot should be. This is the first time you’ve reached out to them and you want to make sure they are able to give as many suggestions as they want (could be 1, could be 3, could be 43). Most importantly, you do not want to be digging through 150 individual long-text responses and creating multiple new Mascot Suggestion records each. The record creation must be done automatically based on User input.

Our solution allows Admins to retrieve multiple individual values from a User’s input in a single Long Text Area field without any additional input!


Here’s the flow we’ve built. It has a Screen for users to add suggestions into a long text field. We then use a combination of Decisions, Assignments, and Loops to extract individual suggestions from the long text.

We’ll go through each of these elements individually below.

Screen: Make Your Suggestion!

Ask your users for their thoughts on the new mascot, and allow them to enter them into the long text field. Now’s a good time to remind them to add them on individual lines (just like when adding a new Picklist value in Salesforce Setup).

One of our users, Steve, has entered four individual suggestions into the long text box.

Assignment: Assign Suggestions

This screen uses a formula called NewSuggestions to populate a text variable called NewSuggestions_var. The reason we use a formula to populate this value instead of the input field itself is so that we can replace the carriage returns (enters, breaks between lines, etc) with a semicolon (;) that the flow can understand. We then add one last semicolon at the end to mark the end of the list (we’ll explain this more later). We use the JSENCODE function to make sure our text string is safe for use in JavaScript (read more about this function here).

Note: We’ll add that formula at the bottom of the article so you can reference it.

Once the NewSuggestions_var has been populated with Steve’s suggestions, it will contain a string (text) value like the below:


Decision: Values are Extracted?

This is a simple step - the criteria check to see if the NewSuggestions_var is empty, which won’t be initially. We’re about to pull individual values from the NewSuggestions_var variable and remove parts of that string until it’s completely empty. Once we’ve removed each individual value, we’ll be able to move to the next step using this Decision element.

Assignment: Add to Suggestions Collection

Once again, we’re using formulae to do some work behind the scene here. This time, we’re using a formula called Current_Suggestion (once again, it’s at the bottom of this article). This formula simply finds the first semicolon in the NewSuggestions_var string, then gets any text before it. The Assignment then adds that string to a Collection Variables called Suggestions_Collection.

Assignment: Remove from New Suggestions Var

Once the first string has been pulled from NewSuggestions_var, we need to remove it. We use a formula called RemoveFirst_Suggestion for this (which refers to another formula called OneNewSuggestionNotTrimmed - both are at the bottom of this post). It finds the first semicolon in the NewSuggestions_var variable and removes it along with anything before it (ie, your first value). The Assignment then sets NewSuggestions_var equal to the value in RemoveFirst_Suggestion formula.

These two assignments repeat for each value in the long text until NewSuggestions_var is completely empty.

Loop: Loop Through Suggestions Collection

This begins a loop - we use a loop variable (text variable in this case) called One_Suggestion to loop through the Suggestions_Collection we’ve already built.

Assignment: Assign to Sobject Variable

A formula called TrimmedValue cleans up the One_Suggestion text variable by removing any remaining spaces before or after it. This value is then assigned to the Name value on an sObject Variable called Suggestion.

Assignment: Assign to Sobject Collection

Now that we have an individual Suggestion sObject variable populated, we’re going to add it to a sObject Collection Variable called SuggestionObj. This is so that we can use a single Fast Create element later on to push all our new records (this is a Salesforce best practice).

Fast Create: Insert Suggestions

Once we have our collection of Suggestions fully populated, it’s time to insert them into the system. Rather than doing this with multiple individual Record Creates (which could exceed your Governor Limits for this transaction), we are using our SuggestionObj collection to push all new records at once.

Screen: Thanks!

This screen simply lets the user know that their suggestions have been submitted successfully.

And that’s it! It’s a lot to learn, but if you build it out you’re bound to wrap your head around it pretty quickly. That’s the beauty of Flows!



JSENCODE({!EnterYourSuggestionsHere}), '\r\n', ';'),
  '\n', ';')
+ ';'


) - 1


{!NewSuggestions_var} , {!OneNewSuggestionNotTrimmed} + ";", ""




) - 1



Fan Yang

Fan is Liquid's Salesforce Consultant