Add getDecimalFieldSum method to domain

This will summarise the Decimal field value

Signed-off-by: WimVelzeboer <wimvelzeboer@protonmail.com>
This commit is contained in:
WimVelzeboer
2021-11-03 15:24:05 +00:00
parent 5b486bc3a2
commit 6eee1acdb6
2 changed files with 28 additions and 4 deletions
@@ -249,6 +249,22 @@ public virtual class fflib_SObjects2
.getDateTimeFieldValues(sObjectField);
}
/**
* @param sObjectField The Schema.SObjectField to get the SUM of
*
* @return The total SUM of the given field
*/
@TestVisible
protected virtual Decimal getDecimalFieldSum(Schema.SObjectField sObjectField)
{
Decimal result = 0;
for (SObject record : getRecords())
{
result += record.get(sObjectField) == null ? 0 : (Decimal) record.get(sObjectField);
}
return result;
}
/**
* @param sObjectField The Schema.SObjectField to get their Id values
*