apex-enterprise-patterns / fflib-apex-common

Common Apex Library supporting Apex Enterprise Patterns and much more!
BSD 3-Clause "New" or "Revised" License
903 stars 514 forks source link

Add domain methods to retrieve maps #406

Open wimvelzeboer opened 2 years ago

wimvelzeboer commented 2 years ago

Often we retrieve data from records in maps, these domain methods will help with avoiding iterations.

Account accounts = Accounts.newInstance(records);
Map<Id, String> accountNameById = accounts.getStringFieldByIdField(Account.AccountName, Account.Id);

instead of:

Account accounts = Accounts.newInstance(records);
Map<Id, String> accountNameById = new Map<Id, String>();
for (Account record : (List<Account) accounts.getRecords())
{
  accountNameById.put(record.Id, record.Name);
}

This change is Reviewable