Menu

count

Counts the number of items within a Collection and places the result into a new variable. While a Collection's number of items can be easily accessed through the Collection value's size() method, this command offers a safer way of doing this as it doesn't cause errors should the target variable have a null value, or not actually hold a Collection value.

Attributes

var

Required
Value type
EL-evaluated
Yes String No
Defines the name of the variable that will receive the number of items as a Number value.
value

Required
Value type
EL-evaluated
Yes Any Yes
The resolved value of this attribute is expected to be the Collection whose items are counted. However, any kind of value is accepted - even null. The result of the count for any non-Collection, non-null value will always be 1, while null results in 0.

Examples

One use for the count command is to find out the number of records a Salesforce data retrieval command managed to retrieve:

<query var="opportunities" select="SELECT Id, Name FROM Opportunity">
<count var="thisManyOppos" value="${opportunities}">

Comments

0 comments