Library allowing collection manipulations in APEX which helps in reducing conditional for loops.
The main goal is to provide all the functionality in a standalone class without much preformance overhead.
Latest version: 0.0.4
- fluent interface within standalone class
- operations chaining
- lazy evaluation
- missing fields detection (not populated, not existing)
Filter accounts whose Name field equals Foo
List<Account> filteredAccounts = Collection.of(accountList)
.filter()
.byField(Account.Name).eq('Foo')
.get();
Filter accounts whose Name field equals Foo and field AnnualRevenue is greater or equal than 150000
List<Account> filteredAccounts = Collection.of(accountList)
.filter()
.byField(Account.Name).eq('Foo')
.andAlso()
.byField(Account.AnnualRevenue).gte(150000)
.get();
Get first account which Name field equals Bar or Foo
List<Account> filteredAccounts = Collection.of(accountList)
.filter()
.byField(Account.Name).eq('Bar')
.orElse()
.byField(Account.Name).eq('Foo')
.getFirst();
Get top 10 accounts which AnnualRevenue field is less or equal than 100000
List<Account> filteredAccounts = Collection.of(accountList)
.filter()
.byField(Account.Name).lte(100000)
.get(10);
Ignore non populated Website field (effectively treating them as null)
List<Account> filteredAccounts = Collection.of(accountList)
.filter()
.ignoreNonPopulatedFields()
.byField(Account.Website).isNull()
.get();
Group accounts by Active__c Boolean field
Map<Object, List<Account>> groupedAccounts = Collection.of(accountList)
.group()
.byField(Account.Active__c)
.get();
Sum accounts AnnualRevenue field values
Decimal sum = Collection.of(accountList)
.reduce()
.byField(Account.AnnualRevenue)
.sum();
Average accounts AnnualRevenue field values
Decimal sum = Collection.of(accountList)
.reduce()
.byField(Account.AnnualRevenue)
.average();
Filter accounts whose Name field equals to Foo then sum matching records AnnualRevenue field
Decimal sum = Collection.of(accountList)
.filter()
.byField(Account.Name).eq('Foo')
.then()
.reduce()
.byField(Account.AnnualRevenue)
.sum();
Filter accounts whose AnnualRevenue field is greater or equal than 100000 then group matching records by BillingCity field
Map<Object, List<Account>> found = Collection.of(accountList)
.filter()
.byField(Account.AnnualRevenue).gte(100000)
.then()
.group()
.byField(Account.BillingCity)
.get();
Currently Set and Map types are not supported for manipulations, only List type
- Introduced breaking changes
- Renamed
mapoperation toreduce - Operation chaining proceeds by
then()call - Changed
isInandisNotInfiltering operations to accept onlyList<Object>values - Improved class test coverage to
91.48%
- Added operations chaining: filter-then-map, filter-then-group
- Added mapping by field operations: sum, average
- Code base refactor
- Initial version
- Added grouping by field operation
- Added filtering by fields operation