Merge pull request #30 from wimvelzeboer/feature/MoreDomainMethods
More domain methods
This commit is contained in:
@@ -585,6 +585,34 @@ public virtual class fflib_SObjects2
|
|||||||
.getLongFieldValues(sObjectField);
|
.getLongFieldValues(sObjectField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestVisible
|
||||||
|
protected virtual List<SObject> getRecords(Schema.SObjectField sObjectField, Set<Id> values)
|
||||||
|
{
|
||||||
|
List<SObject> result = new List<SObject>();
|
||||||
|
for (SObject record : getRecords())
|
||||||
|
{
|
||||||
|
if (values?.contains((Id) record.get(sObjectField)))
|
||||||
|
{
|
||||||
|
result.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestVisible
|
||||||
|
protected virtual List<SObject> getRecords(Schema.SObjectField sObjectField, Set<String> values)
|
||||||
|
{
|
||||||
|
List<SObject> result = new List<SObject>();
|
||||||
|
for (SObject record : getRecords())
|
||||||
|
{
|
||||||
|
if (values?.contains((String) record.get(sObjectField)))
|
||||||
|
{
|
||||||
|
result.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a map with the record mapped to the given Id field value
|
* Get a map with the record mapped to the given Id field value
|
||||||
* Key fields containing null values are omitted
|
* Key fields containing null values are omitted
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
public virtual with sharing class fflib_SObjectUnitOfWork2
|
||||||
|
extends fflib_SObjectUnitOfWork
|
||||||
|
implements fflib_ISObjectUnitOfWork
|
||||||
|
{
|
||||||
|
public fflib_SObjectUnitOfWork2(List<SObjectType> sObjectTypes)
|
||||||
|
{
|
||||||
|
super(sObjectTypes);
|
||||||
|
}
|
||||||
|
public fflib_SObjectUnitOfWork2(List<SObjectType> sObjectTypes, IDML dml)
|
||||||
|
{
|
||||||
|
super(sObjectTypes, dml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void registerDirty(fflib_ISObjects domain)
|
||||||
|
{
|
||||||
|
registerDirty(domain.getRecords());
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>53.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
@@ -482,6 +482,40 @@ private class fflib_SObjects2Test
|
|||||||
System.assert(domain.getFirstSObject().get('Rating') == 'Warm');
|
System.assert(domain.getFirstSObject().get('Rating') == 'Warm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void itShouldGetRecordByIdFieldValues()
|
||||||
|
{
|
||||||
|
final Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
List<Account> records = new List<Account> {
|
||||||
|
new Account(Id = accountId),
|
||||||
|
new Account(Id = fflib_IDGenerator.generate(Schema.Account.SObjectType)),
|
||||||
|
new Account(Id = fflib_IDGenerator.generate(Schema.Account.SObjectType))
|
||||||
|
};
|
||||||
|
fflib_SObjects2 domain = new fflib_SObjects2(records);
|
||||||
|
|
||||||
|
List<SObject> results = domain.getRecords(Schema.Account.Id, new Set<Id> {accountId});
|
||||||
|
|
||||||
|
System.assertEquals(1, results.size());
|
||||||
|
System.assertEquals(accountId, results.get(0).Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void itShouldGetRecordByStringFieldValues()
|
||||||
|
{
|
||||||
|
final String accountName = 'Test';
|
||||||
|
List<Account> records = new List<Account> {
|
||||||
|
new Account(Name = accountName),
|
||||||
|
new Account(Name = accountName + 'A'),
|
||||||
|
new Account(Name = 'Demo')
|
||||||
|
};
|
||||||
|
fflib_SObjects2 domain = new fflib_SObjects2(records);
|
||||||
|
|
||||||
|
List<SObject> results = domain.getRecords(Schema.Account.Name, new Set<String> {accountName});
|
||||||
|
|
||||||
|
System.assertEquals(1, results.size());
|
||||||
|
System.assertEquals(accountName, (String) results.get(0).get(Schema.Account.Name));
|
||||||
|
}
|
||||||
|
|
||||||
@IsTest
|
@IsTest
|
||||||
static void itShouldSetField()
|
static void itShouldSetField()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user