2

I have a screen element where I input the opportunity Ids split by comma. I am wondering if there is a way to split the values by comma and add it to a collection variable so that I can loop through the records.

enter image description here

3 Answers 3

5

The Flow engine can't do this natively, so you'll need an apex action to help with this.

You can create one yourself, or you'll find UnofficialSF already have an action that will do this for you.

https://unofficialsf.com/new-flow-actions-to-convert-csv-strings-to-string-collections-and-vice-versa/

You can use the 'Convert To String Collection' to get a collection of strings from your input.

If you don't want to install the managed package for this, the source code is also available.

4

There is a way to do this using flows. Please follow the below steps: -

  • Resources
    • 2 Collection variables
      • recordIdDisplay_collection: This will contain the final collection output.
        • Data Type: Text
        • Allow multiple values (collection): checked
      • Occurrences_of_comma_collection: Looping collection
        • Data Type: Number
        • Allow multiple values (collection): checked
    • 4 Formulas
      • i_plus_plus: Incrementing i
        • Data Type: Number
        • Decimal Places: 0
        • Formula: {!i} + 1
      • recordIdDisplay_split: Splitting and getting 1st value in recordIdDisplay
        • Data Type: Text
        • Formula: LEFT({!recordIdDisplay_original}, FIND(',', {!recordIdDisplay_original})-1)
      • recordIdDisplay_substitute: Replacing already stored values (in collection) from recordIdDisplay blank (essentially removing)
        • Data Type: Text
        • Formula: SUBSTITUTE({!recordIdDisplay_original}, {!recordIdDisplay_split} & ',', '')
      • Occurrences_of_comma_max: Maximum commas in recordIdDisplay
        • Data Type: Number
        • Decimal Places: 0
        • Formula: (LEN({!$Record.recordIdDisplay}) - LEN(SUBSTITUTE(LOWER({!$Record.recordIdDisplay}),",","")))
    • 3 Variables
      • i: Iterator
        • Data Type: Number
        • Decimal Places: 0
        • Default Value: 0
      • recordIdDisplay_original: Stores updated value of recordIdDisplay after substitution
        • Data Type: Text
        • Default Value: {!$Record.recordIdDisplay}
  • Elements and their order
    1. Assignment (Occurrences_assignment)
      • Variable: {!Occurrences_of_comma_collection}
      • Operator: Add
      • Valu: 0
    2. Loop (For each occurrences of comma)
      • Collection Variable: {!Occurrences_of_comma_collection}
      1. Decision (End Loop?)
        • OUTCOME DETAILS
          • Label: If all comma occurrences finished
          • Condition Requirements to Execute Outcome: All Conditions are Met (AND)
            • Resource: {!Occurrences_of_comma_collection}
            • Operator: Contains
            • Value: {!Occurrences_of_comma_max}
        1. [Path] If all comma occurrences finished
          • Assignment (Assign last value)
            • Variable: {!recordIdDisplay_collection}
            • Operator: Add
            • Value: {!recordIdDisplay_original}
          • End
        2. [Path] Default Outcome
          • Assignment (Assign n-1 values to collection)
              • Variable: {!recordIdDisplay_collection}
              • Operator: Add
              • Value: {!recordIdDisplay_split}
              • Variable: {!i}
              • Operator: Equals
              • Value: {!i_plus_plus}
              • Variable: {!Occurrences_of_comma_collection}
              • Operator: Add
              • Value: {!i}
              • Variable: {!recordIdDisplay_original}
              • Operator: Equals
              • Value: {!recordIdDisplay_substitute}

enter image description here


Hope this helps!
4

I found a nice(r) way of achieving the requested: First I check whether the separator (should be a constant) is contained in the string, if so, the left part is cut into a separate variable and added to the collection (if not empty), then the remaining part is put into the original variable and we start over.

To extract first entry: trim(LEFT({!remainingText}, FIND({!SEPARATOR}, {!remainingText})-1))

To update remaining text: Trim(right({!remainingText}, len({!remainingText})-FIND({!SEPARATOR}, {!remainingText})))

flow which translates a comma separated string into a collection

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .