Add domain method getRecordsContaining (#67)
This commit is contained in:
@@ -793,6 +793,31 @@ public virtual class fflib_SObjects2
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of records where the given field contains the provided value (String.contains)
|
||||||
|
*
|
||||||
|
* @param sObjectField The field to check
|
||||||
|
* @param value The value the field must contain
|
||||||
|
*
|
||||||
|
* @return Returns a list of `SObjects` where the field contains the value
|
||||||
|
*/
|
||||||
|
@TestVisible
|
||||||
|
protected virtual List<SObject> getRecordsContaining(Schema.SObjectField sObjectField, String value)
|
||||||
|
{
|
||||||
|
List<SObject> result = new List<SObject>();
|
||||||
|
for (SObject record : getRecords())
|
||||||
|
{
|
||||||
|
String fieldValue = (String) record.get(sObjectField);
|
||||||
|
if ((fieldValue == null && value == null)
|
||||||
|
||
|
||||||
|
(fieldValue != null && fieldValue.contains(value))
|
||||||
|
) {
|
||||||
|
result.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@TestVisible
|
@TestVisible
|
||||||
protected virtual List<SObject> getRecordsIsNot(Schema.SObjectField sObjectField, String value)
|
protected virtual List<SObject> getRecordsIsNot(Schema.SObjectField sObjectField, String value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ private class fflib_SObjects2Test
|
|||||||
{
|
{
|
||||||
DomainAccounts domain = generateDomain();
|
DomainAccounts domain = generateDomain();
|
||||||
|
|
||||||
System.Assert.istrue(
|
System.Assert.isTrue(
|
||||||
domain.getStringFieldValues(Schema.Account.ShippingCountry)
|
domain.getStringFieldValues(Schema.Account.ShippingCountry)
|
||||||
.containsAll(
|
.containsAll(
|
||||||
new Set<String>
|
new Set<String>
|
||||||
@@ -626,6 +626,16 @@ private class fflib_SObjects2Test
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void itShouldReturnRecordsContainingValue()
|
||||||
|
{
|
||||||
|
DomainAccounts domain = generateDomain();
|
||||||
|
|
||||||
|
List<SObject> records = domain.getRecordsContaining(Schema.Account.ShippingCountry, 'Ire');
|
||||||
|
System.Assert.areEqual(1, records.size());
|
||||||
|
System.Assert.areEqual('B', records.get(0).get('Name'));
|
||||||
|
}
|
||||||
|
|
||||||
@IsTest
|
@IsTest
|
||||||
static void itShouldSetFieldValue()
|
static void itShouldSetFieldValue()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user