Add getDecimalById to fflib_SObjects2
Signed-off-by: WimVelzeboer <william@velzeboer.nl>
This commit is contained in:
@@ -246,6 +246,27 @@ public virtual class fflib_SObjects2
|
||||
.getDateTimeFieldValues(sObjectField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param decimalField The field to use as the Value of the returned Map
|
||||
* @param idField The field to use as the Key of the returned map
|
||||
*
|
||||
* @return Returns a map with the values of two fields
|
||||
*/
|
||||
@TestVisible
|
||||
protected virtual Map<Id, Decimal> getDecimalById(Schema.SObjectField decimalField, Schema.SObjectField idField) {
|
||||
Map<Id, Decimal> result = new Map<Id, Decimal>();
|
||||
for (SObject record : getRecords())
|
||||
{
|
||||
if (record.get(idField) == null) continue;
|
||||
|
||||
result.put(
|
||||
(Id) record.get(idField),
|
||||
(Decimal) record.get(decimalField)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sObjectField The Schema.SObjectField to get the SUM of
|
||||
*
|
||||
|
||||
@@ -165,6 +165,16 @@ private class fflib_SObjects2Test
|
||||
System.Assert.isNull(result.get(caseIdC), 'Case Id B should have no related Account Id');
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnDecimalById() {
|
||||
final Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||
final Account record = new Account(Id = accountId, AnnualRevenue = 123.45);
|
||||
fflib_SObjects2 domain = new fflib_SObjects2(new List<Account>{ record });
|
||||
System.Test.startTest();
|
||||
Map<Id, Decimal> result = domain.getDecimalById(Schema.Account.AnnualRevenue, Schema.Account.Id);
|
||||
System.Test.stopTest();
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnStringById()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user