diff --git a/sfdx-source/apex-extensions/main/default/classes/domains/fflib_SObjects2.cls b/sfdx-source/apex-extensions/main/default/classes/domains/fflib_SObjects2.cls index 02334d1..f2590f3 100644 --- a/sfdx-source/apex-extensions/main/default/classes/domains/fflib_SObjects2.cls +++ b/sfdx-source/apex-extensions/main/default/classes/domains/fflib_SObjects2.cls @@ -793,6 +793,31 @@ public virtual class fflib_SObjects2 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 getRecordsContaining(Schema.SObjectField sObjectField, String value) + { + List result = new List(); + 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 protected virtual List getRecordsIsNot(Schema.SObjectField sObjectField, String value) { diff --git a/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls b/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls index bee698d..ecadadb 100644 --- a/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls +++ b/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls @@ -612,7 +612,7 @@ private class fflib_SObjects2Test { DomainAccounts domain = generateDomain(); - System.Assert.istrue( + System.Assert.isTrue( domain.getStringFieldValues(Schema.Account.ShippingCountry) .containsAll( new Set @@ -626,6 +626,16 @@ private class fflib_SObjects2Test ); } + @IsTest + static void itShouldReturnRecordsContainingValue() + { + DomainAccounts domain = generateDomain(); + + List records = domain.getRecordsContaining(Schema.Account.ShippingCountry, 'Ire'); + System.Assert.areEqual(1, records.size()); + System.Assert.areEqual('B', records.get(0).get('Name')); + } + @IsTest static void itShouldSetFieldValue() {