Hello friends,
Which condition is better to use on IF, Count or Empty ?
or both are equal?
Regards.
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.
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
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.
There's best practise to use .Empty condition only
Aliaksandr Kasko wrote:
Thank you Aliaksandr Kasko
Okay Kilian,
Thanks
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.
Indeed, that's good advice (though slightly off-topic :)).