diff --git a/sfdx-source/apex-common/main/classes/fflib_SObjects.cls b/sfdx-source/apex-common/main/classes/fflib_SObjects.cls index 95c48ccf01..b1849b8872 100644 --- a/sfdx-source/apex-common/main/classes/fflib_SObjects.cls +++ b/sfdx-source/apex-common/main/classes/fflib_SObjects.cls @@ -257,7 +257,7 @@ public virtual class fflib_SObjects { for (SObjectField field : fields) { - if (String.isNotBlank((String) record.get(field))) continue; + if (String.isNotBlank(String.valueOf(record.get(field)))) continue; result.add(record); break; @@ -279,7 +279,7 @@ public virtual class fflib_SObjects Boolean allBlank = true; for (SObjectField field : fields) { - if (String.isNotBlank((String) record.get(field))) + if (String.isNotBlank(String.valueOf(record.get(field)))) { allBlank = false; break; @@ -314,7 +314,7 @@ public virtual class fflib_SObjects { for (SObjectField field : fields) { - if (String.isNotBlank((String) record.get(field))) + if (String.isNotBlank(String.valueOf(record.get(field)))) { result.add(record); break; @@ -337,7 +337,7 @@ public virtual class fflib_SObjects Boolean allNonBlank = true; for (SObjectField field : fields) { - if (String.isBlank((String) record.get(field))) + if (String.isBlank(String.valueOf(record.get(field)))) { allNonBlank = false; break; diff --git a/sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls b/sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls index dd5bd13f0a..92bd0efa46 100644 --- a/sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls +++ b/sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls @@ -102,6 +102,13 @@ private class fflib_SObjectsTest System.assertEquals(3, domain.selectWithoutShippingCountry().size()); } + @IsTest + static void itShouldReturnRecordsWithoutFieldValuesForNonStringFields() + { + DomainAccounts domain = generateDomain(); + + System.assertEquals(4, domain.selectWithoutNumberOfEmployees().size()); + } @IsTest static void itShouldReturnRecordsWithoutAllFieldValues() @@ -118,13 +125,20 @@ private class fflib_SObjectsTest System.assert(domain.selectWithShippingCountry().size() == 4); } + @IsTest + static void itShouldReturnRecordsWithNumberOfEmployees() + { + DomainAccounts domain = generateDomain(); + + System.assert(domain.selectWithNumberOfEmployees().size() == 3); + } @IsTest static void itShouldReturnRecordsWithAllFieldValues() { DomainAccounts domain = generateDomain(); - System.assert(domain.selectPopulatedRecords().size() == 4); + System.assert(domain.selectPopulatedRecords().size() == 2); } @IsTest @@ -151,6 +165,44 @@ private class fflib_SObjectsTest ); } + @IsTest + static void itShouldReturnFieldValuesForNonStringFields() + { + DomainAccounts domain = generateDomain(); + + final Set expectedOriginalType = new Set + { + null, + 10, + 20, + 30 + }; + + System.assert( + domain.getFieldValues(Schema.Account.NumberOfEmployees) + .equals(expectedOriginalType) + ); + } + + @IsTest + static void itShouldReturnStringFieldValuesForNonStringFields() + { + DomainAccounts domain = generateDomain(); + + final Set expectedStrings = new Set + { + null, + '10', + '20', + '30' + }; + + System.assert( + domain.getStringFieldValues(Schema.Account.NumberOfEmployees) + .equals(expectedStrings) + ); + } + @IsTest static void itShouldSetFieldValue() { @@ -212,11 +264,11 @@ private class fflib_SObjectsTest { new Account(Name = 'A', ShippingCountry = 'USA'), new Account(Name = 'B', ShippingCountry = 'Ireland'), - new Account(Name = 'C', ShippingCountry = 'UK'), + new Account(Name = 'C', ShippingCountry = 'UK', NumberOfEmployees = 10), new Account(Name = 'D', ShippingCountry = ''), - new Account(Name = 'E'), + new Account(Name = 'E', NumberOfEmployees = 20), new Account(), - new Account(Name = 'G', ShippingCountry = 'Canada') + new Account(Name = 'G', ShippingCountry = 'Canada', NumberOfEmployees = 30) } ); return domain; @@ -260,13 +312,28 @@ private class fflib_SObjectsTest ); } + public List selectWithoutNumberOfEmployees() + { + return (List) getRecordsWithBlankFieldValues( + Schema.Account.NumberOfEmployees + ); + } + + public List selectWithNumberOfEmployees() + { + return (List) getRecordsWithNotBlankFieldValues( + Schema.Account.NumberOfEmployees + ); + } + public List selectWithEmptyRecord() { return (List) getRecordsWithAllBlankFieldValues( new Set { Schema.Account.Name, - Schema.Account.ShippingCountry + Schema.Account.ShippingCountry, + Schema.Account.NumberOfEmployees } ); } @@ -277,7 +344,8 @@ private class fflib_SObjectsTest new Set { Schema.Account.Name, - Schema.Account.ShippingCountry + Schema.Account.ShippingCountry, + Schema.Account.NumberOfEmployees } ); }