5

I'm working with a product called SDocs which generates PDFs (among other things). I need to pass a comma-delimited String of "names" to generate more than one PDF at once.

The names (datatype: text) are already stored in a collection. Assuming I don't know the size of the Collection, is there a way to do this in a Flow without using Apex? I have no problem using Apex, the customer just prefers "No Code".

Flow Pic

2
  • Please elaborate on what you mean by "The names are already stored in a collection." What Data Type is the Collection Variable?
    – Moonpie
    Commented Aug 20, 2021 at 23:59
  • @Moonpie - As the title says - the Data Type is a "collection of strings (text)". What I'm looking for is to generate a comma-delimited string that is highlighted in yellow in the picture. Commented Aug 21, 2021 at 0:37

2 Answers 2

7

I am sure that there is more than one way to skin a cat, but here is something quick and dirty I came up with....


Prep

enter image description here

  • [A] DocNamesCollection: Text Collection Variable
  • [B] DocNamesList: Text Variable that is NOT a Collection
  • [C] DocNamesCount: Number Variable

Flow

enter image description here

Step 1

This is just assigning "DocName01", "DocName02" and "DocName03" to DocNamesCollection for me to use in the sample Flow.

Step 2

A standard Loop through DocNamesCollection

Step 3

Add 1 to DocNamesCount

Step 4

Simple Decision element to check if DocNamesCount is greater than 1

First time through it will go straight to Step 5; after that, it should go through Step 6

Step 5

Add the current Loop item value to DocNamesList:

enter image description here

Step 6

Add a comma to DocNamesList:

enter image description here


Results

From the Flow debug:

enter image description here


After you exit the loop, you should be able to replace what you have highlighted in your question with the name of the Text List Variable (DocNamesList in the sample).

As stated earlier, there are multiple ways you could do it. If your original Collection of doc names is a Record Collection, you can grab the count directly. If you "manually" build your Collection of doc names earlier in the Flow, you could instead use the above loop, skip building a Collection, and instead directly add on to a non-Collection variable as shown.

2
  • Reading this, I'm having a "why oh why are we not doing this in Apex" moment. developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/… Commented Sep 26 at 18:24
  • 1
    @MatthewSouther: That would have been the answer I and many others would have given three years ago if the OP had not explicitly stated, 'I have no problem using Apex, the customer just prefers "No Code".'
    – Moonpie
    Commented Sep 27 at 22:59
2

This can be done with a simple flow formula: If your original source data is in a Text Collection named DocNamesCollection with the content...

Payload1
Payload2
Payload3
Payload4

...just create a flow formula DocNamesCollectionCsv of type text that reads

{!DocNamesCollection}

This formula will result to

[Payload1,Payload2,Payload3,Payload4]

Apparently you want to get rid of the [], then change the above text formula to

MID({!DocNamesCollection}, 2, LEN({!DocNamesCollection}) - 2)

which will deliver the desired result of

Payload1,Payload2,Payload3,Payload4

If you want to count the number of elements in your collection, just define a Number variable DocNamesCount and use it in an assignment element as follows:

Variable=DocNamesCount | Operator=Equals Count | Value={!DocNamesCollection}

If your source collection happens to come from a record collection, e.g. build a list from Account.Name out of a GetRecords on Account, you can use the Transform element to convert the Account collection into a text collection and do same as above.

Important note:

  • This will fail if your payload contains " as string delimiters will not be escaped.
  • This will fail if your payload contains comma , as the approach cannot distinguish between payload comma and list comma.

If you need to deal with such special cases and/or want to have the string delimiter or the field delimiter configurable, I suggest my BLOG post with a detailed explanation on how to enhance the formulas to achieve this: How to Concatenate a Collection of Strings to a Comma-Delimited String in Salesforce Flow

1
  • Great solution! Commented Sep 26 at 14:34

You must log in to answer this question.

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