Add overloads for decimal values in getRecords and getRecordsNotIn (#77)
* Add overloads for decimal values in getRecords and getRecordsNotIn * updated readme file * Add compatibility for multiselect picklists for the `getRecords` method
This commit is contained in:
@@ -49,16 +49,19 @@ You can also have a look at the open items in the [project(s)](./projects), feel
|
||||
# Change Log
|
||||
Some of the changes that have major impact are listed here;
|
||||
|
||||
### Updates 2026
|
||||
### Updates January 2026
|
||||
- **fflib_ArrayUtils** <br/>
|
||||
_replaceKey_,<br/>Add method to replace the key of a given map.</br>
|
||||
_replaceValue_,<br/>Add three method overloads for merging a source map of idById and replacement map of idByString, idByDecimal or idByBoolean.</br>
|
||||
_mergeMaps_,<br/>Add method overload to merge two maps of idByBoolean,
|
||||
_mergeMaps_,<br/>Add method overload to merge two maps of idByBoolean<br/><br/>
|
||||
- **fflib_SObjects2**<br/>
|
||||
The following methods have been added to the SObjects2 class:<br/>
|
||||
_getBooleanFieldByIdField_<br/>
|
||||
_getParentBooleanFieldById_<br/>
|
||||
_getParentDecimalFieldById_<br/>
|
||||
_getParentStringFieldById_<br/>
|
||||
_getParentStringFieldById_<br/> <br/>
|
||||
Add new method overloads for Decimal values to `getRecords`, `getRecordsNotIn` and `getRecordsIsNot`<br/><br/>
|
||||
Add compatibility for multiselect picklists for the `getRecords` method, by adding a new method overload: `getRecords(Schema.SObjectField sObjectField, Set<String> values, Boolean containsAll)`, and a multi-select picklist check in the method `getRecords(Schema.SObjectField sObjectField, String value)`<br/><br/>
|
||||
- **API Upgrades**
|
||||
Upgraded to API 65.0
|
||||
|
||||
|
||||
@@ -996,6 +996,9 @@ public virtual class fflib_SObjects2
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecords(Schema.SObjectField sObjectField, String value)
|
||||
{
|
||||
if (sObjectField.getDescribe().getType() == DisplayType.MULTIPICKLIST)
|
||||
return getRecords(sObjectField, new Set<String>{value}, true);
|
||||
|
||||
return getRecords(sObjectField, new Set<String>{ value });
|
||||
}
|
||||
|
||||
@@ -1013,6 +1016,47 @@ public virtual class fflib_SObjects2
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the records from the domain matching values in the given multi-select picklist field
|
||||
*
|
||||
* @param sObjectField The SObjectType of the multi-select picklist
|
||||
* @param values The values to filter by
|
||||
* @param containsAll If TRUE the returned records have all the given values, otherwise a record with just one value is also returned
|
||||
*
|
||||
* @return Returns a list of matching SObjects
|
||||
*/
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecords(Schema.SObjectField sObjectField, Set<String> values, Boolean containsAll)
|
||||
{
|
||||
if (sObjectField.getDescribe().getType() != DisplayType.MULTIPICKLIST) return getRecords(sObjectField, values);
|
||||
|
||||
List<SObject> result = new List<SObject>();
|
||||
for (SObject record : getRecords())
|
||||
{
|
||||
String value = (String) record.get(sObjectField);
|
||||
|
||||
if ((value == null && (values == null || values.isEmpty() || values.contains(null))) // if values is empty and the field is empty = match!
|
||||
|| (value != null && containsAll && new Set<String>(value.split(';')).containsAll(values))
|
||||
)
|
||||
{
|
||||
result.add(record);
|
||||
}
|
||||
else if (value != null && containsAll == false)
|
||||
{
|
||||
Set<String> fieldValues = new Set<String>(value.split(';'));
|
||||
for (String fieldValue : fieldValues)
|
||||
{
|
||||
if (values.contains(fieldValue))
|
||||
{
|
||||
result.add(record);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of records where the given field contains the provided value (String.contains)
|
||||
*
|
||||
@@ -1056,6 +1100,24 @@ public virtual class fflib_SObjects2
|
||||
return result;
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecordsIsNot(Schema.SObjectField sObjectField, Decimal value)
|
||||
{
|
||||
return getRecordsNotIn(sObjectField, new Set<Decimal>{ value });
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecordsNotIn(Schema.SObjectField sObjectField, Set<Decimal> values)
|
||||
{
|
||||
List<SObject> result = new List<SObject>();
|
||||
for (SObject record : getRecords())
|
||||
{
|
||||
if (values?.contains((Decimal) record.get(sObjectField))) continue;
|
||||
result.add(record);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecordsIsNot(Schema.SObjectField sObjectField, Id idValue)
|
||||
{
|
||||
@@ -1090,6 +1152,19 @@ public virtual class fflib_SObjects2
|
||||
return result;
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecords(Schema.SObjectField sObjectField, Decimal value)
|
||||
{
|
||||
List<SObject> result = new List<SObject>();
|
||||
for (SObject record : getRecords())
|
||||
{
|
||||
if ((Decimal) record.get(sObjectField) != value) continue;
|
||||
|
||||
result.add(record);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parent Domain SObjectType to SObjectField.relationship field on this domain SObjectType
|
||||
*
|
||||
|
||||
@@ -124,7 +124,9 @@ private class fflib_SObjects2Test
|
||||
domain.getIdFieldValues(Account.Id, criteria);
|
||||
domain.getRecords(Account.Id, domain.getFirstSObject().Id);
|
||||
domain.getRecords(Account.Name, 'A');
|
||||
domain.getRecords(Account.AnnualRevenue, 1.0);
|
||||
domain.getRecordsIsNot(Account.Name, 'A');
|
||||
domain.getRecordsIsNot(Account.AnnualRevenue, 1.0);
|
||||
domain.getRecordsIsNot(Account.Id, domain.getFirstSObject().Id);
|
||||
domain.getSObjectByIdField(Account.Id);
|
||||
domain.getIdFieldValues(Account.Id, true);
|
||||
|
||||
Reference in New Issue
Block a user