Add getBooleanFieldByIdField method to fflib_SObjects2 (#72)
This commit is contained in:
@@ -53,6 +53,9 @@ Some of the changes that have major impact are listed here;
|
||||
- **fflib_ArrayUtils** <br/>
|
||||
_replaceValue_,<br/>Add three method overloads for merging a source map of idById and replacement map of idByString, idByDecimal or idByBoolean.</br>
|
||||
_mergeMaps_,<br/>Add method overload to merge two maps of idByBoolean,
|
||||
- **fflib_SObjects2**<br/>
|
||||
The following methods have been added to the SObjects2 class:<br/>
|
||||
_getBooleanFieldByIdField_
|
||||
- **API Upgrades**
|
||||
Upgraded to API 65.0
|
||||
|
||||
|
||||
@@ -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<Id, Boolean> isDeletedById = account.getBooleanFieldByIdField(Account.IsDeleted, Account.Id);
|
||||
*/
|
||||
@TestVisible
|
||||
protected virtual Map<Id, Boolean> getBooleanFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
|
||||
{
|
||||
Map<Id, Boolean> result = new Map<Id, Boolean>();
|
||||
Map<Object, Object> 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
|
||||
*
|
||||
|
||||
@@ -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<Account>{ record });
|
||||
System.Test.startTest();
|
||||
Map<Id, Decimal> 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<Id, Id> 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<Id> recordIds = new Set<Id> {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<Id> recordIds = new Set<Id> {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<Account> selectByShippingCountry(String country)
|
||||
{
|
||||
return (List<Account>) getRecordsByFieldValues(
|
||||
return getRecordsByFieldValues(
|
||||
Schema.Account.ShippingCountry,
|
||||
new Set<Object> {country}
|
||||
);
|
||||
@@ -750,7 +751,7 @@ private class fflib_SObjects2Test
|
||||
|
||||
public List<Account> selectByRating(String rating)
|
||||
{
|
||||
return (List<Account>) getRecordsByFieldValue(
|
||||
return getRecordsByFieldValue(
|
||||
Schema.Account.Rating,
|
||||
rating
|
||||
);
|
||||
@@ -758,21 +759,21 @@ private class fflib_SObjects2Test
|
||||
|
||||
public List<Account> selectWithoutShippingCountry()
|
||||
{
|
||||
return (List<Account>) getRecordsWithBlankFieldValues(
|
||||
return getRecordsWithBlankFieldValues(
|
||||
Schema.Account.ShippingCountry
|
||||
);
|
||||
}
|
||||
|
||||
public List<Account> selectWithShippingCountry()
|
||||
{
|
||||
return (List<Account>) getRecordsWithNotBlankFieldValues(
|
||||
return getRecordsWithNotBlankFieldValues(
|
||||
Schema.Account.ShippingCountry
|
||||
);
|
||||
}
|
||||
|
||||
public List<Account> selectWithEmptyRecord()
|
||||
{
|
||||
return (List<Account>) getRecordsWithAllBlankFieldValues(
|
||||
return getRecordsWithAllBlankFieldValues(
|
||||
new Set<Schema.SObjectField>
|
||||
{
|
||||
Schema.Account.Name,
|
||||
@@ -783,7 +784,7 @@ private class fflib_SObjects2Test
|
||||
|
||||
public List<Account> selectPopulatedRecords()
|
||||
{
|
||||
return (List<Account>) getRecordsWithAllNotBlankFieldValues(
|
||||
return getRecordsWithAllNotBlankFieldValues(
|
||||
new Set<Schema.SObjectField>
|
||||
{
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user