Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 11 additions & 3 deletions sfdx-source/apex-common/main/classes/fflib_SObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ public virtual class fflib_SObjects
* @return Return a set with all the Id values of the given field
*/
@TestVisible
protected Set<Id> getIdFieldValues(Schema.SObjectField field)
protected virtual Set<Id> getIdFieldValues(Schema.SObjectField field)
{
Set<Id> result = new Set<Id>();
for (SObject record : getRecords())
{
result.add((Id) record.get(field));
if (record.isSet(field))
{
result.add((Id) record.get(field));
}
}
return result;
}
Expand All @@ -177,11 +180,16 @@ public virtual class fflib_SObjects
* @return Return a set with all the String values of the given field
*/
@TestVisible
protected Set<String> getStringFieldValues(Schema.SObjectField field)
protected virtual Set<String> getStringFieldValues(Schema.SObjectField field)
{
Set<String> result = new Set<String>();
for (SObject record : getRecords())
{
if (String.isBlank((String) record.get(field)))
{
continue;
}

result.add((String) record.get(field));
}
return result;
Expand Down
35 changes: 21 additions & 14 deletions sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,29 @@ private class fflib_SObjectsTest
{
DomainAccounts domain = generateDomain();

final Set<String> expected = new Set<String>
{
null,
'',
'Canada',
'Ireland',
'UK',
'USA'
};
System.assert(
domain.getStringFieldValues(Schema.Account.ShippingCountry).equals(expected)
);

// Return only string, omitting nulls and blanks
System.assertEquals(
new Set<String>
{
'Canada',
'Ireland',
'UK',
'USA'
},
domain.getStringFieldValues(Schema.Account.ShippingCountry));

// Return all the values, including nulls and blanks
System.assert(
domain.getFieldValues(Schema.Account.ShippingCountry)
.equals(expected)
.equals(new Set<String>
{
'Canada',
'Ireland',
'UK',
'USA',
'',
null
})
);
}

Expand Down