diff --git a/README.md b/README.md
index 584d00d..76b57ff 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,9 @@ Some of the changes that have major impact are listed here;
- **fflib_ArrayUtils**
_replaceValue_, Add three method overloads for merging a source map of idById and replacement map of idByString, idByDecimal or idByBoolean.
_mergeMaps_, Add method overload to merge two maps of idByBoolean,
+- **fflib_SObjects2**
+ The following methods have been added to the SObjects2 class:
+ _getBooleanFieldByIdField_
- **API Upgrades**
Upgraded to API 65.0
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 f2590f3..8680ab9 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
@@ -67,6 +67,31 @@ public virtual class fflib_SObjects2
SObjectDescribe = sObjectType.getDescribe();
}
+ /**
+ * Get a map with the given Boolean field value mapped to the given Id field
+ * Key fields containing null values are omitted
+ *
+ * @param valueField The Boolean field to use as value for the map
+ * @param keyField The Id field to use as key for the map
+ *
+ * @return a map with the given Boolean field value mapped to the given Id field
+ *
+ * @example
+ * Account account = Account.newInstance(records);
+ * Map isDeletedById = account.getBooleanFieldByIdField(Account.IsDeleted, Account.Id);
+ */
+ @TestVisible
+ protected virtual Map getBooleanFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
+ {
+ Map result = new Map();
+ Map fieldByField = getFieldByField(valueField, keyField);
+ for (Object obj : fieldByField.keySet())
+ {
+ result.put((Id) obj, (Boolean) fieldByField.get(obj));
+ }
+ return result;
+ }
+
/**
* @param id Domain containing primary key (Id field) values
*
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 ecadadb..c0a1366 100644
--- a/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls
+++ b/sfdx-source/apex-extensions/tests/classes/domains/fflib_SObjects2Test.cls
@@ -115,6 +115,7 @@ private class fflib_SObjects2Test
domain.getSObjectsByIdField(Account.Id);
domain.getSObjectByStringField(Account.Name);
domain.getSObjectsByStringField(Account.Name);
+ domain.getBooleanFieldByIdField(Account.IsDeleted, Account.Id);
domain.getStringFieldByStringField(Account.Name, Account.AccountNumber);
domain.getStringFieldValues(Account.Name, criteria);
domain.stripInaccessibleFields();
@@ -308,7 +309,7 @@ private class fflib_SObjects2Test
final Account record = new Account(Id = accountId, AnnualRevenue = 123.45);
fflib_SObjects2 domain = new fflib_SObjects2(new List{ record });
System.Test.startTest();
- Map result = domain.getDecimalById(Schema.Account.AnnualRevenue, Schema.Account.Id);
+ domain.getDecimalById(Schema.Account.AnnualRevenue, Schema.Account.Id);
System.Test.stopTest();
}
@@ -366,7 +367,7 @@ private class fflib_SObjects2Test
System.Test.stopTest();
System.Assert.areEqual(1, result.size(), 'Incorrect returned amount of results');
- System.Assert.istrue(result.keySet().contains(accountId), 'The accountId is missing from the results');
+ System.Assert.isTrue(result.keySet().contains(accountId), 'The accountId is missing from the results');
System.Assert.areEqual(today, result.get(accountId), 'Incorrect returned date');
}
@@ -394,11 +395,11 @@ private class fflib_SObjects2Test
System.Test.stopTest();
System.Assert.areEqual(2, result.size(), 'Incorrect amount of results');
- System.Assert.istrue(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
- System.Assert.istrue(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
System.Assert.areEqual(1, result2.size(), 'Incorrect amount of results');
- System.Assert.istrue(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
}
@IsTest
@@ -425,11 +426,11 @@ private class fflib_SObjects2Test
System.Test.stopTest();
System.Assert.areEqual(2, result.size(), 'Incorrect amount of results');
- System.Assert.istrue(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
- System.Assert.istrue(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
System.Assert.areEqual(1, result2.size(), 'Incorrect amount of results');
- System.Assert.istrue(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
+ System.Assert.isTrue(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
}
@IsTest
@@ -442,7 +443,7 @@ private class fflib_SObjects2Test
System.Test.startTest();
Map accountIdByContactId = domain.getIdFieldByIdField(Schema.Contact.AccountId, Schema.Contact.Id);
System.Test.stopTest();
- System.Assert.istrue(accountIdByContactId.containsKey(contactId));
+ System.Assert.isTrue(accountIdByContactId.containsKey(contactId));
System.Assert.areEqual(accountId, accountIdByContactId.get(contactId));
}
@@ -464,7 +465,7 @@ private class fflib_SObjects2Test
);
Set recordIds = new Set {idA, idB, idC};
- System.Assert.istrue(
+ System.Assert.isTrue(
domain.getSObjectById().keySet().containsAll(recordIds),
'The domain should return all the record Ids'
);
@@ -488,7 +489,7 @@ private class fflib_SObjects2Test
);
Set recordIds = new Set {idA, idB, idC};
- System.Assert.istrue(
+ System.Assert.isTrue(
domain.getRecordIds().containsAll(recordIds),
'The domain should return all the record Ids'
);
@@ -742,7 +743,7 @@ private class fflib_SObjects2Test
public List selectByShippingCountry(String country)
{
- return (List) getRecordsByFieldValues(
+ return getRecordsByFieldValues(
Schema.Account.ShippingCountry,
new Set {country}
);
@@ -750,7 +751,7 @@ private class fflib_SObjects2Test
public List selectByRating(String rating)
{
- return (List) getRecordsByFieldValue(
+ return getRecordsByFieldValue(
Schema.Account.Rating,
rating
);
@@ -758,21 +759,21 @@ private class fflib_SObjects2Test
public List selectWithoutShippingCountry()
{
- return (List) getRecordsWithBlankFieldValues(
+ return getRecordsWithBlankFieldValues(
Schema.Account.ShippingCountry
);
}
public List selectWithShippingCountry()
{
- return (List) getRecordsWithNotBlankFieldValues(
+ return getRecordsWithNotBlankFieldValues(
Schema.Account.ShippingCountry
);
}
public List selectWithEmptyRecord()
{
- return (List) getRecordsWithAllBlankFieldValues(
+ return getRecordsWithAllBlankFieldValues(
new Set
{
Schema.Account.Name,
@@ -783,7 +784,7 @@ private class fflib_SObjects2Test
public List selectPopulatedRecords()
{
- return (List) getRecordsWithAllNotBlankFieldValues(
+ return getRecordsWithAllNotBlankFieldValues(
new Set
{
Schema.Account.Name,
@@ -805,11 +806,6 @@ private class fflib_SObjects2Test
ratingByCountry);
}
- public void addNameError(String message)
- {
- addError(Schema.Account.Name, message);
- }
-
public void clearShippingCountry()
{
clearField(Schema.Account.ShippingCountry);