588
Views
8
Comments
Solved
Which condition is better, Count or Empty ?
Question

Hello friends,

Which condition is better to use on IF, Count or Empty ?

or both are equal?

Regards.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Agno,

For determining whether a List is empty, always use Empty. This is because if the list is coming from an Aggregate or SQL, using Count will actually force the Platform to execute another query just to retrieve the number of records (there are good reasons for this). For a List that's not coming from a query, e.g. from a REST service or the like (or from a query, but via an Output Variable of an Action), it doesn't matter what you use, but since you'd have to be aware everytime you use a List, just always use Empty to test for an empty list.

2025-03-19 01-45-51
Sandeep Kumar Kolli

Hi @Kilian Hekhuis, is List.Empty and List.Length have the same impact? Or any performance issues.

So is it okay to use either Lenght or Empty or it's not the same, please explian

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

For checking whether a List is empty, best practice is to use Empty. Using Length is just not semantically right, even though when a List is empty, a check on List.Length = 0 would work. Use Length only when you are interested in the actual Length of a List, though be careful with checking it when it's the output of an Aggregte or SQL, as Length will not be the total number of records, just the number of records fetched.

2019-10-30 14-18-23
Aliaksandr Kasko

Hi Agno,

There's best practise to use .Empty condition only

2021-06-09 13-39-18
Agno Silveira
 
MVP

Aliaksandr Kasko wrote:

Hi Agno,

There's best practise to use .Empty condition only

Thank you Aliaksandr Kasko


2021-06-09 13-39-18
Agno Silveira
 
MVP

Okay Kilian,

Thanks

2021-12-03 11-52-42
Arjan van de Wiel

In addition to that, when counting the actual number of rows you can even setup a new query for more performance.

Not including all relations and attributes can speed up your counting query.


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Indeed, that's good advice (though slightly off-topic :)).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.