Just found this article on Salesforce Time showing how to avoid duplicates in a collection.
(1st image) It uses a loop/assignment with a Remove All then Add - this will remove all duplicates from the list and then add the element back to the list.
🔗 LINK to the Salesforce Time article: https://lnkd.in/gUE8_K7T
⛔ 🚫 EDIT: What I described below is NOT recommended because there are side effects when removing items from the collection being looped over.
🙏 Thanks to Piotr Kożuchowski for pointing that out! 🙏
That reminded me of something similar I had done so I've found this post:
🔗 LINK to my post of 9 months ago: https://www.linkedin.com/posts/fernandofernandez1_how-to-remove-duplicates-from-activity-7230551453013004290-nOIG
(2nd image) It was supposed to accomplish almost the same thing in the reverse order: Add then Remove All.
First: adds the element to the list of unique items
Then: removes the element from the original list (the same list which is being looped over)
But that was wrong! 🤦♂️
I assumed since this is Flow, there would be no side effects modifying the list we are iterating over. There are some languages where this is permitted and the resulting behavior is defined. NOT Flows.
Removing items from a collection in a loop will result in the loop ending sooner but the side effect is that some items will be skipped!
👉 So don't remove items from the collection that is being looped over!

