findWhere System Method

findWhere System Method
lac51
Use the 
findWhere
 system method to filter or sort a list. This method returns a filtered and sorted collection. Logic often requires searching lists to verify whether objects are present, for example:
  • Inclusion
    . Assure that a row is included.
    For example, an Employee might have two child collections of languages: 
    spokenLanguage
     and 
    translatesLanguage
    . You can ensure that each spoken language has a row for that user/language in 
    spokenLanguage
    .
  • Exclusion
    . Assure that a row is excluded.
    For example, in a Bill of Materials definition, you can ensure that a component is not also the containing part.
Example
The following is used in the 
allocateFromTo
 system method:
SysLogic.findWhere(
row.paymentCustomer.ordersList, // input collection
"row.amount_un_paid > 0", // filter
"placed_date a") // sort
Parameters:
 Input collection (often a child accessor, as shown here for payments), filter, and sort.
For more information about this example, see The allocateFromTo System Method.
Performance
The 
findWhere
 construct queries the input collection from the database and performs an in-memory filter/sort. It leverages the transaction cache. It is a good choice if the input collection is small or if the input collection is re-used in the transaction. If the input collection is large, use a SQL SELECT statement.