Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sfdx-source/apex-common/main/classes/fflib_SObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public virtual class fflib_SObjects
Set<String> result = new Set<String>();
for (SObject record : getRecords())
{
result.add((String) record.get(field));
result.add(String.valueOf(record.get(field)));
}
return result;
}
Expand Down Expand Up @@ -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;
Comment thread
john-storey-devops marked this conversation as resolved.

result.add(record);
break;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
80 changes: 74 additions & 6 deletions sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -151,6 +165,44 @@ private class fflib_SObjectsTest
);
}

@IsTest
static void itShouldReturnFieldValuesForNonStringFields()
{
DomainAccounts domain = generateDomain();

final Set<Integer> expectedOriginalType = new Set<Integer>
{
null,
10,
20,
30
};

System.assert(
domain.getFieldValues(Schema.Account.NumberOfEmployees)
.equals(expectedOriginalType)
);
}

@IsTest
static void itShouldReturnStringFieldValuesForNonStringFields()
{
DomainAccounts domain = generateDomain();

final Set<String> expectedStrings = new Set<String>
{
null,
'10',
'20',
'30'
};

System.assert(
domain.getStringFieldValues(Schema.Account.NumberOfEmployees)
.equals(expectedStrings)
);
}

@IsTest
static void itShouldSetFieldValue()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -260,13 +312,28 @@ private class fflib_SObjectsTest
);
}

public List<Account> selectWithoutNumberOfEmployees()
{
return (List<Account>) getRecordsWithBlankFieldValues(
Schema.Account.NumberOfEmployees
);
}

public List<Account> selectWithNumberOfEmployees()
{
return (List<Account>) getRecordsWithNotBlankFieldValues(
Schema.Account.NumberOfEmployees
);
}

public List<Account> selectWithEmptyRecord()
{
return (List<Account>) getRecordsWithAllBlankFieldValues(
new Set<Schema.SObjectField>
{
Schema.Account.Name,
Schema.Account.ShippingCountry
Schema.Account.ShippingCountry,
Schema.Account.NumberOfEmployees
}
);
}
Expand All @@ -277,7 +344,8 @@ private class fflib_SObjectsTest
new Set<Schema.SObjectField>
{
Schema.Account.Name,
Schema.Account.ShippingCountry
Schema.Account.ShippingCountry,
Schema.Account.NumberOfEmployees
}
);
}
Expand Down