Skip to content

Commit e632990

Browse files
committed
Merge remote-tracking branch 'ffdev-origin/master'
Conflicts: fflib/src/classes/fflib_SObjectSelector.cls fflib/src/classes/fflib_SObjectUnitOfWork.cls
2 parents 4c38538 + 0a9d4e8 commit e632990

36 files changed

+2031
-281
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ Dreamforce Session and Slides
3636
- View slides for the **Dreamforce 2013** session [here](https://docs.google.com/file/d/0B6brfGow3cD8RVVYc1dCX2s0S1E/edit)
3737
- Video recording of the **Dreamforce 2013** session [here](http://www.youtube.com/watch?v=qlq46AEAlLI).
3838
- Video recording of the **Advanced Apex Enterprise Dreamforce 2014** session [here](http://dreamforce.vidyard.com/watch/7QtP2628KmtXfmiwI-7B1w%20).
39+
- View slides for the **Dreamforce 2015** session [here](http://www.slideshare.net/andyinthecloud/building-strong-foundations-apex-enterprise-patterns)
3940

4041
Documentation
4142
-------------
4243

43-
I'm proud to have been given the opportunity to run a more detailed look at these patterns on developer.force.com.
44-
44+
- [Apex Sharing and applying to Apex Enterprise Patterns](http://andyinthecloud.com/2016/01/10/apex-sharing-and-applying-to-apex-enterprise-patterns/)
45+
- [Tips for Migrating to Apex Enterprise Patterns](http://andyinthecloud.com/2015/09/30/tips-for-migrating-to-apex-enterprise-patterns/)
46+
- [Great Contributions to Apex Enterprise Patterns](http://andyinthecloud.com/2015/07/25/great-contributions-to-apex-enterprise-patterns/)
4547
- [Unit Testing, Apex Enterprise Patterns and ApexMocks – Part 1](http://andyinthecloud.com/2015/03/22/unit-testing-with-apex-enterprise-patterns-and-apexmocks-part-1/)
4648
- [Unit Testing, Apex Enterprise Patterns and ApexMocks – Part 2](http://andyinthecloud.com/2015/03/29/unit-testing-apex-enterprise-patterns-and-apexmocks-part-2/)
4749
- [Apex Enterprise Patterns - Separation of Concerns](http://wiki.developerforce.com/page/Apex_Enterprise_Patterns_-_Separation_of_Concerns)

fflib/src/classes/fflib_Application.cls

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ public class fflib_Application
6262
return new fflib_SObjectUnitOfWork(m_objectTypes);
6363
}
6464

65+
/**
66+
* Returns a new fflib_SObjectUnitOfWork configured with the
67+
* SObjectType list specified, returns a Mock implementation
68+
* if set via the setMock method
69+
*
70+
* @remark If mock is set, the list of SObjectType in the mock could be different
71+
* then the list of SObjectType specified in this method call
72+
**/
73+
public fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes)
74+
{
75+
// Mock?
76+
if(m_mockUow!=null)
77+
return m_mockUow;
78+
return new fflib_SObjectUnitOfWork(objectTypes);
79+
}
80+
6581
@TestVisible
6682
private void setMock(fflib_ISObjectUnitOfWork mockUow)
6783
{
@@ -288,6 +304,37 @@ public class fflib_Application
288304
return (fflib_ISObjectDomain) domainConstructor.construct(records);
289305
}
290306

307+
/**
308+
* Dynamically constructs an instace of the Domain class for the given records and SObjectType
309+
* Will return a Mock implementation if one has been provided via setMock
310+
*
311+
* @param records A list records
312+
* @param domainSObjectType SObjectType for list of records
313+
* @exception Throws an exception if the SObjectType is not specified or if constructor for Domain class was not registered for the SObjectType
314+
*
315+
* @remark Will support List<SObject> but all records in the list will be assumed to be of
316+
* the type specified in sObjectType
317+
**/
318+
public fflib_ISObjectDomain newInstance(List<SObject> records, SObjectType domainSObjectType)
319+
{
320+
if(domainSObjectType==null)
321+
throw new DeveloperException('Must specify sObjectType');
322+
323+
// Mock implementation?
324+
if(m_sObjectByMockDomain.containsKey(domainSObjectType))
325+
return m_sObjectByMockDomain.get(domainSObjectType);
326+
327+
// Determine SObjectType and Apex classes for Domain class
328+
Type domainConstructorClass = m_sObjectByDomainConstructorType.get(domainSObjectType);
329+
if(domainConstructorClass==null)
330+
throw new DeveloperException('Domain constructor class not found for SObjectType ' + domainSObjectType);
331+
332+
// Construct Domain class passing in the queried records
333+
fflib_SObjectDomain.IConstructable2 domainConstructor =
334+
(fflib_SObjectDomain.IConstructable2) domainConstructorClass.newInstance();
335+
return (fflib_ISObjectDomain) domainConstructor.construct(records, domainSObjectType);
336+
}
337+
291338
@TestVisible
292339
private void setMock(fflib_ISObjectDomain mockDomain)
293340
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>31.0</apiVersion>
3+
<apiVersion>37.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

0 commit comments

Comments
 (0)