Is it possible to loop through two collections and compare values?

I would like to look up values on the Contact object and compare them to values in a Custom Metadata object. The Contact object will be updated if mailing address data on the Contact Object matches data in the Custom Metadata Object.

I know that this could be done using fast look up and comparing one record at a time to the Custom Meta Data collection and maybe that is the best way? I am just used to using fast lookups for everything.

Flow with One Loop Flow with two loops

  • Can you elaborate on what data points you need to compare? The Flow contains operator supports checking collection contents if you have a collection of primitive values (i.e., strings).
    – David Reed
    Commented Jul 2, 2018 at 15:13
  • All strings. Does the contact city, state or zip code match with certain city state or zip code data from the Custom Meta data. If it matches then update the contact. With a lookup, I would just add the contact fields to individual variables and compare them to the collection. I can't figure out how to compare two collections of if that is even a good way to do it. Commented Jul 2, 2018 at 15:37
  • This is an auto-launched flow and I thought going with a fast lookup would make more sense during bulk uploads instead of a lookup that gets one record at a time. Commented Jul 2, 2018 at 15:54

1 Answer 1


I think this challenge can be approached using string collection variables. It's tough to describe an imagined Flow, but I think it'd go something like this:

Fast Lookup for Custom Metadata Records
--> Loop over Custom Metadata Records
-----> For each record, add its key values (City, State, ZIP) to individual collection variables - i.e., one collection variable per data point you want to compare.

Source your Contacts (could be a Fast Lookup)
--> Loop over Contacts
-----> For each Contact, make a Decision
--------> If each key data point collection variable (City, State, ZIP) contains the
          value present on this Contact, update the data on this Contact as desired.

Perform a Fast Update of your Contact list.

I don't think you'll be able to approach it as comparing a list of addresses to a list of addresses; Flow doesn't have Address as an first-class type. You could do that in Apex with a Set of a custom class that implements hashCode() (although it wouldn't be an especially natural idiom there either).

Breaking it down into specific data points and ANDing criteria (listOfCities CONTAINS contactsCity AND listOfZIPs CONTAINS contactsZip AND...) is going to fit the bill for this application.

  • I don't seem to be able to find a way to make a flow with two variables work. I built one but with the current layout it stops running after the first loop. I built a second flow with one loop. It does what I need it to do in the debug testing. But I am not sure iti is the best solution for bulk uploads. Commented Jul 2, 2018 at 21:16
  • I am adding pics to the orignial post Commented Jul 2, 2018 at 21:17
  • 1
    I think, Brooks, in your second Flow you need to connect your end-of-loop outcome to Fast Update a collection of influencers rather than doing it as part of the loop action. But I am not an expert in Flow optimization; I generally use Apex for this kind of challenge.
    – David Reed
    Commented Jul 2, 2018 at 22:09

You must log in to answer this question.

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