Remove Objects

The interface structure was incompatible so had to remove it and replace it again with fflib_Objects
This commit is contained in:
Wim Velzeboer
2021-06-25 09:53:06 +01:00
parent c669623273
commit 694f7a84a2
13 changed files with 160 additions and 125 deletions
+84
View File
@@ -0,0 +1,84 @@
# fflib-apex-extensions
## Primitive Domain - SObject
This class should be used to extend Domain classes.
```apex
public class Accounts extends SObjects implements IAccounts
{
...
}
```
### Method reference
Public methods
- [getSObjectById](#getSObjectById)
- [getRecords](#getRecords)
Protected methods
- [addError](#adderror)
- [clearField / clearFields](#clearField)
- [getDateFieldValues](#getDateFieldValues)
- [getDateTimeFieldValues](#getDateTimeFieldValues)
- [getDecimalFieldValues](#getDecimalFieldValues)
#### getSObjectById
Returns the contents of the Domain by their primary Key ('Id' field)
`public Map<Id, SObject> getSObjectById()`
<br/><br/>
#### getRecords
Returns only the SObjects from the domain matching the given Ids.
`public List<SObject> getRecords(Ids ids)`<br/>
`public List<SObject> getRecords(Set<Id> ids)`<br/>
<br/>
Return the SObject records contained in the domain matching the criteria
- `public List<SObject> getRecords(fflib_Criteria criteria)`<br/>
<br/><br/>
#### addError
Adds an error message to the records in the domain
`protected void addError(String message)`<br/>
`protected void addError(Schema.SObjectField sObjectField, String message)`
<br/><br/>
#### clearField
Clear the field value on all the records of the domain
`protected void clearField(Schema.SObjectField sObjectField)`<br/>
`protected void clearFields(Set<Schema.SObjectField> sObjectFields)`
<br/><br/>
#### getDateFieldValues
Get the Date values from the given SObjectField, null values will be omitted.
If a criteria is provided, only the value of the records matches the criteria will be returned.
`protected Dates getDateFieldValues(Schema.SObjectField sObjectField)`<br/>
`protected Dates getDateFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)`
<br/><br/>
#### getDateTimeFieldValues
Get the Datetime values from the given SObjectField, null values will be omitted.
If a criteria is provided, only the value of the records matches the criteria will be returned.
`protected DateTimes getDateTimeFieldValues(Schema.SObjectField sObjectField)`<br/>
`protected DateTimes getDateTimeFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)`
<br/><br/>
#### getDecimalFieldValues
Get the Decimal values from the given SObjectField, null values will be omitted.
If a criteria is provided, only the value of the records matches the criteria will be returned.
`protected Decimals getDecimalFieldValues(Schema.SObjectField sObjectField)`<br/>
`protected Decimals getDecimalFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)`
+10
View File
@@ -19,4 +19,14 @@ One other benefit is that you can encapsulate more logic as Lists. You can see t
Take a look at the SObjects primitive domain, it is the new source for extending domain classes.
### Available Primitive Domains
- Dates
- DateTimes
- Decimals
- Doubles
- Ids
- Integers
- Longs
- [SObjects](domains/sobject.md)
- Strings
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class DateTimes
extends Objects
extends fflib_Objects
{
public DateTimes(Set<Datetime> dateTimes)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual class Dates
extends Objects
extends fflib_Objects
{
public Dates(Set<Date> dates)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Decimals
extends Objects
extends fflib_Objects
{
public Decimals(Set<Decimal> decimals)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Doubles
extends Objects
extends fflib_Objects
{
public Doubles(Set<Double> doubles)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Ids
extends Objects
extends fflib_Objects
{
public Ids(Set<Id> idSet)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Integers
extends Objects
extends fflib_Objects
{
public Integers(Set<Integer> integerSet)
{
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Longs
extends Objects
extends fflib_Objects
{
public Longs(Set<Long> longs)
{
@@ -1,90 +0,0 @@
/**
* File Name: Objects
* Description: Primitive domain for the object type Object
*
* @author : architect ir. Wilhelmus G.J. Velzeboer
*
* Copyright (c), W.G.J. Velzeboer,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above author notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Objects
extends fflib_Objects
implements fflib_IObjects
{
// The objects contained in the domain
protected List<Object> objects { get; private set; }
// The object type of the objects contained in the domain
private Object objectType;
/**
* Class constructor
*
* @param obj The object to contain inside the domain
*/
public Objects(Object obj)
{
this(new List<Object>{ obj });
}
/**
* Class constructor
*
* @param objects The objects to contain inside the domain
*/
public Objects(Set<Object> objects)
{
this(new List<Object>(objects));
}
/**
* Class constructor
*
* @param objects The objects to contain inside the domain
*/
public Objects(List<Object> objects)
{
this(objects, Object.class);
}
/**
* Class constructor
*
* @param objects The objects to contain inside the domain
* @param objectType The object type of the given objects
*/
public Objects(List<Object> objects, Object objectType)
{
super(objects);
this.objectType = this.objectType;
}
/**
* @return Returns a unique set of objects which are contained in the domain
*/
public Set<Object> getObjectsSet()
{
return new Set<Object>(getObjects());
}
}
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<status>Active</status>
</ApexClass>
@@ -67,13 +67,67 @@ public virtual class SObjects
SObjectDescribe = sObjectType.getDescribe();
}
/**
* @return Returns the contents of the Domain by their primary Key ('Id' field)
*/
public virtual Map<Id, SObject> getSObjectById()
{
return new Map<Id, SObject>(getRecords());
}
/**
* @param ids Domain containing primary key (Id field) values
*
* @return Returns only the SObjects from the domain matching the given Ids.
*/
public virtual List<SObject> getRecords(Ids ids)
{
return getRecords(ids.getIds());
}
/**
* @param ids A Set containing primary key (Id field) values
*
* @return Returns only the SObjects from the domain matching the given Ids.
*/
public virtual List<SObject> getRecords(Set<Id> ids)
{
Map<Id, SObject> sObjectsByIds = getSObjectById();
List<SObject> result = new List<SObject>();
for (Id id : ids)
{
if (sObjectsByIds.containsKey(id) == false) continue;
result.add(sObjectsByIds.get(id));
}
return result;
}
/**
* @param criteria The condition the returned record must meet
*
* @return Return the SObject records contained in the domain matching the criteria
*/
public virtual List<SObject> getRecords(fflib_Criteria criteria)
{
List<SObject> result = new List<SObject>();
for (SObject record : getRecords())
{
if (!criteria.evaluate(record)) continue;
result.add(record);
}
return result;
}
/**
* Adds an error message to the records in the domain
*
* @param message The error message to add to each record
*/
@TestVisible
protected void addError(String message)
protected virtual void addError(String message)
{
for (SObject record : getRecords())
{
@@ -88,7 +142,7 @@ public virtual class SObjects
* @param message The error message to add to the given field on each record
*/
@TestVisible
protected void addError(Schema.SObjectField sObjectField, String message)
protected virtual void addError(Schema.SObjectField sObjectField, String message)
{
for (SObject record : getRecords())
{
@@ -101,7 +155,7 @@ public virtual class SObjects
* @param sObjectField The field to nullify
*/
@TestVisible
protected void clearField(Schema.SObjectField sObjectField)
protected virtual void clearField(Schema.SObjectField sObjectField)
{
clearFields(new Set<Schema.SObjectField>{ sObjectField });
}
@@ -111,7 +165,7 @@ public virtual class SObjects
* @param sObjectFields The fields to nullify
*/
@TestVisible
protected void clearFields(Set<Schema.SObjectField> sObjectFields)
protected virtual void clearFields(Set<Schema.SObjectField> sObjectFields)
{
for (SObject record : getRecords())
{
@@ -340,24 +394,6 @@ public virtual class SObjects
.getLongFieldValues(sObjectField);
}
/**
* @param criteria The condition the returned record must meet
*
* @return Return the SObject records contained in the domain
*/
@TestVisible
public virtual List<SObject> getRecords(fflib_Criteria criteria)
{
List<SObject> result = new List<SObject>();
for (SObject record : getRecords())
{
if (!criteria.evaluate(record)) continue;
result.add(record);
}
return result;
}
/**
* @param sObjectField The Schema.SObjectField to get their values
*
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public virtual with sharing class Strings
extends Objects
extends fflib_Objects
{
public Strings(Set<String> stringSet)
{