How to Remove Duplicates Using Assignment Operators in Flow

How to Remove Duplicates Using Assignment Operators in Flow

A collection variable in Flow is an ordered list that holds multiple values of the same data type. In some scenarios, the same item might appear more than once in the collection, leading to unnecessary duplicates. When this happens, you may want to filter out the duplicates and keep only the unique values. In this post, you will learn how to remove duplicates and build a unique collection using collection assignment operators in Flow.

Using the Remove All and Add Operators to Remove Duplicates

You can remove duplicates in Flow by using the Remove All and Add collection assignment operators. However, it's important to note that this method only works for exact duplicates. It means items that are completely identical.

For example, if you have two different Contact records with the same email address, they are still considered separate records and won't be treated as duplicates by this method. On the other hand, if you're combining two record collections and a specific record exists in both, this method will ensure that the record appears only once in the final collection.

Let's build a flow to build a text collection of email addresses of Contact records.

1- Add a Get Records element to get the Contact records that meet the criteria.

Get Contact Records

2- Create a text collection to store the email addresses.

We want to add email addresses to a text collection. If you simply use the Add operator, it will add all the email addresses, even if some are duplicates. This can result in duplicate items when multiple contacts share the same email address.

One of the most common ways to ensure that each item appears only once in a collection is by using a Decision element to check if the item already exists before adding it. However, there's a simpler method: using the Remove All operator. Here is how to achieve this.

Add Loop and Assignment elements to your Flow. Then, configure the Assignment element as follows:

Using the Collection Assignment Operators to Remove Duplicates

The Remove All operator removes the current item from the collection, and then the Add operator adds it back. This ensures that each item appears only once in the collection. This method works for record variables too.

End of the Flow

As you can see, there are 5 Contact records with 3 unique email addresses.

Remove Duplicates

Read this post to learn how to convert text collection to bullet list in Flow.

1 Trackback / Pingback

  1. Convert Text Collection to Bullet List in Flow - Salesforce Time

Leave a Reply

Your email address will not be published.


*