Collection
Test A Collection is an ordered sequence of other values. Its worth lies in certain commands' ability to loop through all the items of a Collection, doing something to, or with, each item individually. Collections typically appear in the logic generated by Salesforce queries, as the data-retrieval operations that find more than one record produce a Collection of Data items.
Note that while the values within a Collection do not have to be of the same type, it is highly recommended as all commands within loops are generally expecting to handle values of a certain type. Therefore, be careful with addItem
commands - be sure to add values of the same type as those already in the Collection!
Instead of looping through all items with specific commands, it is also possible to access items individually by their index. The indexes start with 0, so an expression like ${collection[0]}
would get the Collection's first item. Specifying an index that's greater than the Collection's length results in an error, though, so any logic using this feature should also use the size()
method to find out the maximum index.
Related commands
setCollection & addItem These commands can be used to create new Collections within the logic. They come useful in more advanced solutions in which creating internal custom data models for tables and such become necessary.
forEach The loop command that allows the logic to do something with each item in a Collection.
sortCollection Allows the creation of a new Collection with the contents of an existing Collection in a sorted order.
Methods
contains(value) | Resolves into a Boolean telling whether the Collection contains the specified value (true) or not (false). For example, to check if a Collection of Strings called 'wordsCollection' contains a String "Test", the expression |
isEmpty() | Resolves into a Boolean telling whether the Collection has no items (true) or not (false). For example, the expression |
size() | Resolves into a Number representing the number of items in the Collection. For example, if 'queryResults' was a Collection produced by a Salesforce query, |