Merge branch 'main' into main
This commit is contained in:
@@ -22,6 +22,64 @@ public inherited sharing class ${NAME}
|
||||
return (List<${SObject_API_Name}>) getRecords();
|
||||
}
|
||||
|
||||
public I${NAME} selectById(Set<Id> ids)
|
||||
{
|
||||
return new ${NAME}(getRecords(ids));
|
||||
}
|
||||
|
||||
private I${NAME} selectBy(fflib_Criteria criteria)
|
||||
{
|
||||
return new ${NAME}(getRecords(criteria));
|
||||
}
|
||||
|
||||
private I${NAME} selectBlank(Schema.SObjectField sObjectField)
|
||||
{
|
||||
List<${SObject_API_Name}> result = new List<${SObject_API_Name}>();
|
||||
for (${SObject_API_Name} record : get${NAME}())
|
||||
{
|
||||
if (String.isNotBlank((String) record.get(sObjectField))) continue;
|
||||
|
||||
result.add(record);
|
||||
}
|
||||
return new ${NAME}(result);
|
||||
}
|
||||
|
||||
private I${NAME} selectNonBlank(Schema.SObjectField sObjectField)
|
||||
{
|
||||
List<${SObject_API_Name}> result = new List<${SObject_API_Name}>();
|
||||
for (${SObject_API_Name} record : get${NAME}())
|
||||
{
|
||||
if (String.isBlank((String) record.get(sObjectField))) continue;
|
||||
|
||||
result.add(record);
|
||||
}
|
||||
return new ${NAME}(result);
|
||||
}
|
||||
|
||||
private I${NAME} selectWith(Schema.SObjectField sObjectField)
|
||||
{
|
||||
List<${SObject_API_Name}> result = new List<${SObject_API_Name}>();
|
||||
for (${SObject_API_Name} record : get${NAME}())
|
||||
{
|
||||
if (record.get(sObjectField) == null) continue;
|
||||
|
||||
result.add(record);
|
||||
}
|
||||
return new ${NAME}(result);
|
||||
}
|
||||
|
||||
private I${NAME} selectWithout(Schema.SObjectField sObjectField)
|
||||
{
|
||||
List<${SObject_API_Name}> result = new List<${SObject_API_Name}>();
|
||||
for (${SObject_API_Name} record : get${NAME}())
|
||||
{
|
||||
if (record.get(sObjectField) != null) continue;
|
||||
|
||||
result.add(record);
|
||||
}
|
||||
return new ${NAME}(result);
|
||||
}
|
||||
|
||||
public class Constructor implements fflib_IDomainConstructor
|
||||
{
|
||||
public fflib_SObjects construct(List<Object> records)
|
||||
|
||||
@@ -2,4 +2,5 @@ public interface I${NAME}
|
||||
extends fflib_ISObjects
|
||||
{
|
||||
List<${SObject_API_Name}> get${NAME}();
|
||||
I${NAME} selectById(Set<Id> ids);
|
||||
}
|
||||
@@ -713,7 +713,7 @@ public virtual class fflib_SObjects2
|
||||
protected virtual Map<Id, String> getStringFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
|
||||
{
|
||||
Map<Id, String> result = new Map<Id, String>();
|
||||
Map<Object, Object> fieldByField = getFieldByField(keyField, valueField);
|
||||
Map<Object, Object> fieldByField = getFieldByField(valueField, keyField);
|
||||
for (Object obj : fieldByField.keySet())
|
||||
{
|
||||
result.put((Id) obj, (String) fieldByField.get(obj));
|
||||
|
||||
@@ -15,4 +15,15 @@ public with sharing class fflib_MockSObjectUtil
|
||||
JSON.serialize(parentObject) + '}',
|
||||
SObject.class);
|
||||
}
|
||||
|
||||
public static SObject addFieldValue(
|
||||
SObject record, SObjectField sObjectField, Object value)
|
||||
{
|
||||
String original = JSON.serialize(record);
|
||||
return (SObject) JSON.deserialize(
|
||||
original.left(original.length() - 1) + ',"'
|
||||
+ sObjectField.getDescribe().getName() + '":"'
|
||||
+ String.valueOf(value) + '"}',
|
||||
SObject.class);
|
||||
}
|
||||
}
|
||||
@@ -108,8 +108,6 @@ private class fflib_SObjects2Test
|
||||
domain.getIdFieldsByIdField(Account.Id, Account.Id);
|
||||
domain.getIdFieldValues(Account.Id);
|
||||
domain.getIdFieldValues(Account.Id, criteria);
|
||||
domain.getIntegerFieldValues(Account.NumberOfEmployees);
|
||||
domain.getIntegerFieldValues(Account.NumberOfEmployees, criteria);
|
||||
domain.getDecimalFieldValues(Account.BillingLatitude, criteria);
|
||||
domain.getDoubleFieldValues(Account.BillingLatitude);
|
||||
domain.getDoubleFieldValues(Account.BillingLatitude, criteria);
|
||||
@@ -117,7 +115,6 @@ private class fflib_SObjects2Test
|
||||
domain.getSObjectsByIdField(Account.Id);
|
||||
domain.getSObjectByStringField(Account.Name);
|
||||
domain.getSObjectsByStringField(Account.Name);
|
||||
domain.getStringFieldByIdField(Account.Id, Account.Name);
|
||||
domain.getStringFieldByStringField(Account.Name, Account.AccountNumber);
|
||||
domain.getStringFieldValues(Account.Name, criteria);
|
||||
|
||||
@@ -137,6 +134,89 @@ private class fflib_SObjects2Test
|
||||
System.assertEquals(accountId, nameById.get(accountId));
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnStringFieldByIdField()
|
||||
{
|
||||
final String accountName = 'My Account';
|
||||
final Id accountId = fflib_IDGenerator.generate(Account.SObjectType);
|
||||
DomainAccounts domain = new DomainAccounts(
|
||||
new List<Account>
|
||||
{
|
||||
new Account(Id = accountId, Name = accountName),
|
||||
new Account(Name = accountName + ' 2') // This one should be ignored
|
||||
});
|
||||
|
||||
System.Test.startTest();
|
||||
Map<Id, String> result = domain.getStringFieldByIdField(Account.Name, Account.Id);
|
||||
System.Test.stopTest();
|
||||
|
||||
System.assertEquals(1, result.size(), 'Incorrect returned amount of results');
|
||||
System.assert(result.keySet().contains(accountId), 'The accountId is missing from the results');
|
||||
System.assertEquals(accountName, result.get(accountId), 'Incorrect returned account name');
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnIntegerFieldValues()
|
||||
{
|
||||
final Integer numberOfEmployees = 10;
|
||||
final String accountName = 'Test Account';
|
||||
DomainAccounts domain = new DomainAccounts(
|
||||
new List<Account>
|
||||
{
|
||||
new Account(NumberOfEmployees = numberOfEmployees),
|
||||
new Account(Name = accountName, NumberOfEmployees = numberOfEmployees * 2),
|
||||
new Account() // This one should be ignored
|
||||
});
|
||||
|
||||
System.Test.startTest();
|
||||
Set<Integer> result = domain.getIntegerFieldValues(Account.NumberOfEmployees).getIntegerSet();
|
||||
Set<Integer> result2 =
|
||||
domain.getIntegerFieldValues(
|
||||
Account.NumberOfEmployees,
|
||||
new fflib_Criteria().equalTo(Schema.Account.Name, accountName)
|
||||
)
|
||||
.getIntegerSet();
|
||||
System.Test.stopTest();
|
||||
|
||||
System.assertEquals(2, result.size(), 'Incorrect amount of results');
|
||||
System.assert(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
|
||||
System.assert(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
|
||||
|
||||
System.assertEquals(1, result2.size(), 'Incorrect amount of results');
|
||||
System.assert(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnLongFieldValues()
|
||||
{
|
||||
final Integer numberOfEmployees = 10;
|
||||
final String accountName = 'Test Account';
|
||||
DomainAccounts domain = new DomainAccounts(
|
||||
new List<Account>
|
||||
{
|
||||
new Account(NumberOfEmployees = numberOfEmployees),
|
||||
new Account(Name = accountName, NumberOfEmployees = numberOfEmployees * 2),
|
||||
new Account() // This one should be ignored
|
||||
});
|
||||
|
||||
System.Test.startTest();
|
||||
Set<Long> result = domain.getLongFieldValues(Account.NumberOfEmployees).getLongSet();
|
||||
Set<Long> result2 =
|
||||
domain.getLongFieldValues(
|
||||
Account.NumberOfEmployees,
|
||||
new fflib_Criteria().equalTo(Schema.Account.Name, accountName)
|
||||
)
|
||||
.getLongSet();
|
||||
System.Test.stopTest();
|
||||
|
||||
System.assertEquals(2, result.size(), 'Incorrect amount of results');
|
||||
System.assert(result.contains(numberOfEmployees), 'The expected numberOfEmployees was not returned');
|
||||
System.assert(result.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
|
||||
|
||||
System.assertEquals(1, result2.size(), 'Incorrect amount of results');
|
||||
System.assert(result2.contains(numberOfEmployees * 2), 'The expected numberOfEmployees was not returned');
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnRecordIdById()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user