The Difference Between a Collection Being "Empty" vs. "Null"

Today I ran into a small issue with one of my flows that I think is a valuable lesson to share. My flow was failing, but the logic in my If Condition seemed correct at first glance.

I wanted the flow to check if it had found a list (a collection) of items If it found items, it would process them. If not, it would follow a different path.


The Common Mistake

My first instinct was to use the If Condition to check if the collection of steps "Is Not Null."

The logic feels right: if the collection is not null, it must contain something, so we can proceed. However, the flow faulted. The error message showed that we were trying to get data from a collection that had no items in it.

This is because there is a critical difference between a collection that is null and a collection that is simply empty.


The Key Difference: Null vs. Empty

It's helpful to think of a collection like a box.

  • Is Null / Is Not Null: This condition checks if the box itself exists. If a collection is null, it means there is no box at all.

  • Count > 0: This condition checks if there are any items inside the box.

You can have a perfectly fine box (so it is not null), but it can have zero items inside it (its count is 0). My flow was failing because the box existed, but it was empty. I was trying to pull an item out of an empty box.


The Solution and Best Practice ✅

When you are working with a collection or a list and you need to process the items inside it, the most reliable method is to check the number of items.

Instead of checking if Collection is not null, change your If Condition to check if the Collection.Count "Is Greater Than" 0.

By checking if the number of items is greater than zero, you ensure that the collection not only exists and also has items in it that your flow can safely process.

After I made this small change, my flow ran perfectly.