Which condition is better, Count or Empty ?

Hello friends,

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

or both are equal?

Regards.

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.

Solution

Hi Agno,

There's best practise to use .Empty condition only

Okay Kilian,

Thanks

Aliaksandr Kasko wrote:

Hi Agno,

There's best practise to use .Empty condition only

Thank you Aliaksandr Kasko


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 :)).