| Show: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fflib_SObjectDomain
Copyright (c), FinancialForce.com, inc 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 copyright 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 FinancialForce.com, inc 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.
Signature
public virtual with sharing class fflib_SObjectDomain
fflib_SObjectDomain Properties
fflib_SObjectDomain Constructors
fflib_SObjectDomain(sObjectList)
Constructs the domain class with the data on which to apply the behaviour implemented within
Signature
public fflib_SObjectDomain(List<SObject> sObjectList)
Parameters
sObjectList
Type:
List<SObject>
A concrete list (e.g. List<Account> vs List<SObject>) of records
fflib_SObjectDomain(sObjectList, sObjectType)
Constructs the domain class with the data and type on which to apply the behaviour implemented within @remark Will support List<SObject> but all records in the list will be assumed to be of the type specified in sObjectType
Signature
public fflib_SObjectDomain(List<SObject> sObjectList, SObjectType sObjectType)
Parameters
sObjectList
Type:
List<SObject>
A list (e.g. List<Opportunity>, List<Account>, etc.) of records
sObjectType
Type:
SObjectType
The Schema.SObjectType of the records contained in the list
fflib_SObjectDomain Methods
error(message, record)
Ensures logging of errors in the Domain context for later assertions in tests
Signature
public override String error(String message, SObject record)
error(message, record, field)
Ensures logging of errors in the Domain context for later assertions in tests
Signature
public override String error(String message, SObject record, SObjectField field)
getChangedRecords(fieldNames)
Detects whether any values in context records have changed for given fields as strings Returns list of SObject records that have changes in the specified fields
Signature
public List<SObject> getChangedRecords(Set<String> fieldNames)
getChangedRecords(fieldTokens)
Detects whether any values in context records have changed for given fields as tokens Returns list of SObject records that have changes in the specified fields
Signature
public List<SObject> getChangedRecords(Set<Schema.SObjectField> fieldTokens)
getTriggerEvent(domainClass)
Signature
public static TriggerEvent getTriggerEvent(Type domainClass)
getTriggerInstance(domainClass)
For Domain classes implementing the ITriggerStateful interface returns the instance of the domain class being shared between trigger invocations, returns null if the Domain class trigger has not yet fired or the given domain class does not implement the ITriggerStateful interface. Note this method is sensitive to recursion, meaning it will return the applicable domain instance for the level of recursion
Signature
public static fflib_SObjectDomain getTriggerInstance(Type domainClass)
handleAfterDelete()
Base handler for the Apex Trigger event After Delete, checks object security and calls the onAfterDelete method @throws DomainException if the current user context is not able to delete records
Signature
public virtual void handleAfterDelete()
handleAfterInsert()
Base handler for the Apex Trigger event After Insert, checks object security and calls the onValidate and onAfterInsert methods @throws DomainException if the current user context is not able to create records
Signature
public virtual void handleAfterInsert()
handleAfterUndelete()
Base handler for the Apex Trigger event After Undelete, checks object security and calls the onAfterUndelete method @throws DomainException if the current user context is not able to delete records
Signature
public virtual void handleAfterUndelete()
handleAfterUpdate(existingRecords)
Base handler for the Apex Trigger event After Update, checks object security and calls the onValidate, onValidate(Map<Id,SObject>) and onAfterUpdate methods @throws DomainException if the current user context is not able to update records
Signature
public virtual void handleAfterUpdate(Map<Id,SObject> existingRecords)
handleBeforeDelete()
Base handler for the Apex Trigger event Before Delete, calls the onBeforeDelete method
Signature
public virtual void handleBeforeDelete()
handleBeforeInsert()
Base handler for the Apex Trigger event Before Insert, calls the onApplyDefaults method, followed by onBeforeInsert
Signature
public virtual void handleBeforeInsert()
handleBeforeUpdate(existingRecords)
Base handler for the Apex Trigger event Before Update, calls the onBeforeUpdate method
Signature
public virtual void handleBeforeUpdate(Map<Id,SObject> existingRecords)
onAfterDelete()
Override this to perform processing during the after delete phase, this is called by the handleAfterDelete method
Signature
public virtual void onAfterDelete()
onAfterInsert()
Override this to perform processing during the after insert phase, this is called by the handleAfterInsert method
Signature
public virtual void onAfterInsert()
onAfterUndelete()
Override this to perform processing during the after undelete phase, this is called by the handleAfterDelete method
Signature
public virtual void onAfterUndelete()
onAfterUpdate(existingRecords)
Override this to perform processing during the after update phase, this is called by the handleAfterUpdate method
Signature
public virtual void onAfterUpdate(Map<Id,SObject> existingRecords)
onApplyDefaults()
Override this to apply defaults to the records, this is called by the handleBeforeInsert method
Signature
public virtual void onApplyDefaults()
onBeforeDelete()
Override this to perform processing during the before delete phase, this is called by the handleBeforeDelete method
Signature
public virtual void onBeforeDelete()
onBeforeInsert()
Override this to perform processing during the before insert phase, this is called by the handleBeforeInsert method
Signature
public virtual void onBeforeInsert()
onBeforeUpdate(existingRecords)
Override this to perform processing during the before update phase, this is called by the handleBeforeUpdate method
Signature
public virtual void onBeforeUpdate(Map<Id,SObject> existingRecords)
onValidate()
Override this to apply general validation to be performed during insert or update, called by the handleAfterInsert and handleAfterUpdate methods
Signature
public virtual void onValidate()
onValidate(existingRecords)
Override this to apply validation to be performed during insert, called by the handleAfterUpdate method
Signature
public virtual void onValidate(Map<Id,SObject> existingRecords)
popTriggerInstance(domainClass, records)
Pops from the stack of domain classes per type a domain object instance and updates the record set
Signature
private static fflib_SObjectDomain popTriggerInstance(Type domainClass, List<SObject> records)
pushTriggerInstance(domainClass, domain)
Pushes to the stack of domain classes per type a domain object instance
Signature
private static void pushTriggerInstance(Type domainClass, fflib_SObjectDomain domain)
sObjectType()
Returns the SObjectType this Domain class represents
Signature
public SObjectType sObjectType()
triggerHandler(domainClass)
Method constructs the given Domain class with the current Trigger context before calling the applicable override methods such as beforeInsert, beforeUpdate etc.
Signature
public static void triggerHandler(Type domainClass)
triggerHandler(domainClass, isBefore, isAfter, isInsert, isUpdate, isDelete, isUndelete, newRecords, oldRecordsMap)
Calls the applicable override methods such as beforeInsert, beforeUpdate etc. based on a Trigger context
Signature
private static void triggerHandler(Type domainClass, Boolean isBefore, Boolean isAfter, Boolean isInsert, Boolean isUpdate, Boolean isDelete, Boolean isUndelete, List<SObject> newRecords, Map<Id, SObject> oldRecordsMap)
fflib_SObjectDomain.Configuration
Fluent style Configuration system for Domain class creation
Signature
public class Configuration
fflib_SObjectDomain.Configuration Properties
fflib_SObjectDomain.Configuration Constructors
Configuration()
Default configuration
Signature
public Configuration()
fflib_SObjectDomain.Configuration Methods
disableOldOnUpdateValidateBehaviour()
See associated property
Signature
public Configuration disableOldOnUpdateValidateBehaviour()
disableTriggerCRUDSecurity()
See associated property
Signature
public Configuration disableTriggerCRUDSecurity()
disableTriggerState()
See associated property
Signature
public Configuration disableTriggerState()
enableOldOnUpdateValidateBehaviour()
See associated property
Signature
public Configuration enableOldOnUpdateValidateBehaviour()
enableTriggerState()
See associated property
Signature
public Configuration enableTriggerState()
enforceTriggerCRUDSecurity()
See associated property
Signature
public Configuration enforceTriggerCRUDSecurity()
fflib_SObjectDomain.DomainException
General exception class for the domain layer
Signature
public class DomainException extends Exception
fflib_SObjectDomain.Error
DEPRECATED, This class has been moved to fflib_SObjects
Signature
public abstract class Error
fflib_SObjectDomain.Error Properties
fflib_SObjectDomain.ErrorFactory
DEPRECATED, This class has been moved to fflib_SObjects
Signature
public class ErrorFactory
fflib_SObjectDomain.ErrorFactory Properties
fflib_SObjectDomain.ErrorFactory ConstructorsErrorFactory()
Signature
private ErrorFactory()
fflib_SObjectDomain.ErrorFactory Methods
clearAll()
Signature
public void clearAll()
error(message, record)
Signature
public String error(String message, SObject record)
error(domain, message, record)
Signature
private String error(fflib_SObjectDomain domain, String message, SObject record)
error(message, record, field)
Signature
public String error(String message, SObject record, SObjectField field)
error(domain, message, record, field)
Signature
private String error(fflib_SObjectDomain domain, String message, SObject record, SObjectField field)
getAll()
Signature
public List<Error> getAll()
fflib_SObjectDomain.FieldError
DEPRECATED, This class has been moved to fflib_SObjects
Signature
public virtual class FieldError extends ObjectError
fflib_SObjectDomain.FieldError Properties
fflib_SObjectDomain.FieldError ConstructorsFieldError()
Signature
public FieldError()
fflib_SObjectDomain.IConstructable
Interface used to aid the triggerHandler in constructing instances of Domain classes
Signature
public interface IConstructable
fflib_SObjectDomain.IConstructable Methodsconstruct(sObjectList)
Signature
fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.IConstructable2
Interface used to aid the triggerHandler in constructing instances of Domain classes
Signature
public interface IConstructable2 extends IConstructable
fflib_SObjectDomain.IConstructable2 Methodsconstruct(sObjectList, sObjectType)
Signature
fflib_SObjectDomain construct(List<SObject> sObjectList, SObjectType sObjectType)
fflib_SObjectDomain.MockDatabase
Class used during Unit testing of Domain classes, can be used (not exclusively) to speed up test execution and focus testing
Signature
public class MockDatabase
fflib_SObjectDomain.MockDatabase Properties
fflib_SObjectDomain.MockDatabase ConstructorsMockDatabase()
Signature
private MockDatabase()
fflib_SObjectDomain.MockDatabase Methods
hasRecords()
Signature
public Boolean hasRecords()
onDelete(records)
Signature
public void onDelete(Map<Id, SObject> records)
onInsert(records)
Signature
public void onInsert(List<SObject> records)
onUndelete(records)
Signature
public void onUndelete(List<SObject> records)
onUpdate(records, oldRecords)
Signature
public void onUpdate(List<SObject> records, Map<Id, SObject> oldRecords)
testTriggerHandler(domainClass)
Signature
private void testTriggerHandler(Type domainClass)
fflib_SObjectDomain.ObjectError
DEPRECATED, This class has been moved to fflib_SObjects
Signature
public virtual class ObjectError extends Error
fflib_SObjectDomain.ObjectError Properties
fflib_SObjectDomain.ObjectError ConstructorsObjectError()
Signature
public ObjectError()
fflib_SObjectDomain.TestFactory
Provides test context mocking facilities to unit tests testing domain classes
Signature
public class TestFactory
fflib_SObjectDomain.TestFactory Properties
fflib_SObjectDomain.TestFactory ConstructorsTestFactory()
Signature
private TestFactory()
fflib_SObjectDomain.TestSObjectChangedRecords
Test domain class (ideally this would be in the test class, however Type.newInstance does not see such classes)
Signature
public with sharing class TestSObjectChangedRecords
fflib_SObjectDomain.TestSObjectChangedRecords ConstructorsTestSObjectChangedRecords(sObjectList)
Signature
public TestSObjectChangedRecords(List<Opportunity> sObjectList)
fflib_SObjectDomain.TestSObjectChangedRecordsConstructor
Typically an inner class to the domain class, supported here for test purposes
Signature
public class TestSObjectChangedRecordsConstructor implements fflib_SObjectDomain.IConstructable
fflib_SObjectDomain.TestSObjectChangedRecordsConstructor Methodsconstruct(sObjectList)
Signature
public fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.TestSObjectDisableBehaviour
Test domain class (ideally this would be in the test class, however Type.newInstance does not see such classes)
Signature
public with sharing class TestSObjectDisableBehaviour
fflib_SObjectDomain.TestSObjectDisableBehaviour ConstructorsTestSObjectDisableBehaviour(sObjectList)
Signature
public TestSObjectDisableBehaviour(List<Opportunity> sObjectList)
fflib_SObjectDomain.TestSObjectDisableBehaviour Methods
onAfterDelete()
Signature
public override void onAfterDelete()
onAfterInsert()
Signature
public override void onAfterInsert()
onAfterUndelete()
Signature
public override void onAfterUndelete()
onAfterUpdate(existing)
Signature
public override void onAfterUpdate(map<id, SObject> existing)
onBeforeDelete()
Signature
public override void onBeforeDelete()
onBeforeInsert()
Signature
public override void onBeforeInsert()
onBeforeUpdate(existing)
Signature
public override void onBeforeUpdate(map<id, SObject> existing)
fflib_SObjectDomain.TestSObjectDisableBehaviourConstructor
Typically an inner class to the domain class, supported here for test purposes
Signature
public class TestSObjectDisableBehaviourConstructor implements fflib_SObjectDomain.IConstructable
fflib_SObjectDomain.TestSObjectDisableBehaviourConstructor Methodsconstruct(sObjectList)
Signature
public fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.TestSObjectDomain
Test domain class (ideally this would be in the test class, however Type.newInstance does not see such classes)
Signature
public with sharing class TestSObjectDomain extends fflib_SObjectDomain
fflib_SObjectDomain.TestSObjectDomain Properties
fflib_SObjectDomain.TestSObjectDomain ConstructorsTestSObjectDomain(sObjectList)
Signature
public TestSObjectDomain(List<Opportunity> sObjectList)
TestSObjectDomain(sObjectList, sObjectType)
Signature
public TestSObjectDomain(List<Opportunity> sObjectList, SObjectType sObjectType)
fflib_SObjectDomain.TestSObjectDomain Methods
onAfterInsert()
Signature
public override void onAfterInsert()
onAfterUndelete()
Signature
public override void onAfterUndelete()
onApplyDefaults()
Signature
public override void onApplyDefaults()
onBeforeDelete()
Signature
public override void onBeforeDelete()
onBeforeInsert()
Signature
public override void onBeforeInsert()
onValidate()
Signature
public override void onValidate()
onValidate(existingRecords)
Signature
public override void onValidate(Map<Id,SObject> existingRecords)
fflib_SObjectDomain.TestSObjectDomainConstructor
Typically an inner class to the domain class, supported here for test purposes
Signature
public class TestSObjectDomainConstructor implements fflib_SObjectDomain.IConstructable
fflib_SObjectDomain.TestSObjectDomainConstructor Methodsconstruct(sObjectList)
Signature
public fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.TestSObjectOnValidateBehaviour
Test domain class (ideally this would be in the test class, however Type.newInstance does not see such classes)
Signature
public with sharing class TestSObjectOnValidateBehaviour
fflib_SObjectDomain.TestSObjectOnValidateBehaviour ConstructorsTestSObjectOnValidateBehaviour(sObjectList)
Signature
public TestSObjectOnValidateBehaviour(List<Opportunity> sObjectList)
fflib_SObjectDomain.TestSObjectOnValidateBehaviour MethodsonValidate()
Signature
public override void onValidate()
fflib_SObjectDomain.TestSObjectOnValidateBehaviourConstructor
Typically an inner class to the domain class, supported here for test purposes
Signature
public class TestSObjectOnValidateBehaviourConstructor implements fflib_SObjectDomain.IConstructable
fflib_SObjectDomain.TestSObjectOnValidateBehaviourConstructor Methodsconstruct(sObjectList)
Signature
public fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.TestSObjectStatefulDomain
Test domain class (ideally this would be in the test class, however Type.newInstance does not see such classes)
Signature
public with sharing class TestSObjectStatefulDomain
fflib_SObjectDomain.TestSObjectStatefulDomain Properties
fflib_SObjectDomain.TestSObjectStatefulDomain ConstructorsTestSObjectStatefulDomain(sObjectList)
Signature
public TestSObjectStatefulDomain(List<Opportunity> sObjectList)
fflib_SObjectDomain.TestSObjectStatefulDomain MethodsonAfterInsert()
Signature
public override void onAfterInsert()
onBeforeInsert()
Signature
public override void onBeforeInsert()
fflib_SObjectDomain.TestSObjectStatefulDomainConstructor
Typically an inner class to the domain class, supported here for test purposes
Signature
public class TestSObjectStatefulDomainConstructor implements fflib_SObjectDomain.IConstructable
fflib_SObjectDomain.TestSObjectStatefulDomainConstructor Methodsconstruct(sObjectList)
Signature
public fflib_SObjectDomain construct(List<SObject> sObjectList)
fflib_SObjectDomain.TriggerEvent
Signature
public class TriggerEvent
fflib_SObjectDomain.TriggerEvent Properties
fflib_SObjectDomain.TriggerEvent ConstructorsTriggerEvent()
Signature
public TriggerEvent()
fflib_SObjectDomain.TriggerEvent Methods
disableAfterDelete()
Signature
public TriggerEvent disableAfterDelete()
disableAfterInsert()
Signature
public TriggerEvent disableAfterInsert()
disableAfterUndelete()
Signature
public TriggerEvent disableAfterUndelete()
disableAfterUpdate()
Signature
public TriggerEvent disableAfterUpdate()
disableAll()
Signature
public TriggerEvent disableAll()
disableAllAfter()
Signature
public TriggerEvent disableAllAfter()
disableAllBefore()
Signature
public TriggerEvent disableAllBefore()
disableBeforeDelete()
Signature
public TriggerEvent disableBeforeDelete()
disableBeforeInsert()
Signature
public TriggerEvent disableBeforeInsert()
disableBeforeUpdate()
Signature
public TriggerEvent disableBeforeUpdate()
enableAfterDelete()
Signature
public TriggerEvent enableAfterDelete()
enableAfterInsert()
Signature
public TriggerEvent enableAfterInsert()
enableAfterUndelete()
Signature
public TriggerEvent enableAfterUndelete()
enableAfterUpdate()
Signature
public TriggerEvent enableAfterUpdate()
enableAll()
Signature
public TriggerEvent enableAll()
enableAllAfter()
Signature
public TriggerEvent enableAllAfter()
enableAllBefore()
Signature
public TriggerEvent enableAllBefore()
enableBeforeDelete()
Signature
public TriggerEvent enableBeforeDelete()
enableBeforeInsert()
Signature
public TriggerEvent enableBeforeInsert()
enableBeforeUpdate()
Signature
public TriggerEvent enableBeforeUpdate()
isEnabled(isBefore, isAfter, isInsert, isUpdate, isDelete, isUndelete)
Signature
public boolean isEnabled(Boolean isBefore, Boolean isAfter, Boolean isInsert, Boolean isUpdate, Boolean isDelete, Boolean isUndelete)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||