Skip to content

Commit 0a5c8b6

Browse files
committed
resolve out of order relationships is static throughout life of unit of work
1 parent 19edc33 commit 0a5c8b6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

fflib/src/classes/fflib_SObjectUnitOfWork.cls

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,41 @@ public virtual class fflib_SObjectUnitOfWork
109109
this(sObjectTypes,new SimpleDML());
110110
}
111111

112+
/**
113+
* Constructs a new UnitOfWork to support work against the given object list
114+
*
115+
* @param sObjectTypes A list of objects given in dependency order (least dependent first)
116+
* @param resolveOutOfOrderRelationships If true and a relationship is registered where a parent is inserted after a
117+
* child then will update the child post-insert to set the relationship. If
118+
* false then relationship will not be set.
119+
*/
120+
public fflib_SObjectUnitOfWork(List<Schema.SObjectType> sObjectTypes, Boolean resolveOutOfOrderRelationships) {
121+
this(sObjectTypes, new SimpleDML(), resolveOutOfOrderRelationships);
122+
}
112123

124+
/**
125+
* Constructs a new UnitOfWork to support work against the given object list
126+
*
127+
* @param sObjectTypes A list of objects given in dependency order (least dependent first)
128+
* @param resolveOutOfOrderRelationships If true and a relationship is registered where a parent is inserted after a
129+
* child then will update the child post-insert to set the relationship. If
130+
* false then relationship will not be set.
131+
*/
113132
public fflib_SObjectUnitOfWork(List<Schema.SObjectType> sObjectTypes, IDML dml)
133+
{
134+
this(sObjectTypes, dml, false);
135+
}
136+
137+
/**
138+
* Constructs a new UnitOfWork to support work against the given object list
139+
*
140+
* @param sObjectTypes A list of objects given in dependency order (least dependent first)
141+
* @param dml Modify the database via this class
142+
* @param resolveOutOfOrderRelationships If true and a relationship is registered where a parent is inserted after a
143+
* child then will update the child post-insert to set the relationship. If
144+
* false then relationship will not be set.
145+
*/
146+
public fflib_SObjectUnitOfWork(List<Schema.SObjectType> sObjectTypes, IDML dml, Boolean resolveOutOfOrderRelationships)
114147
{
115148
m_sObjectTypes = sObjectTypes.clone();
116149

@@ -125,6 +158,10 @@ public virtual class fflib_SObjectUnitOfWork
125158
m_workList.add(m_emailWork);
126159

127160
m_dml = dml;
161+
162+
if (resolveOutOfOrderRelationships) {
163+
attemptToResolveOutOfOrderRelationships();
164+
}
128165
}
129166

130167
// default implementations for commitWork events
@@ -144,7 +181,7 @@ public virtual class fflib_SObjectUnitOfWork
144181
*
145182
* @return this unit of work
146183
*/
147-
public fflib_SObjectUnitOfWork attemptToResolveOutOfOrderRelationships()
184+
private fflib_SObjectUnitOfWork attemptToResolveOutOfOrderRelationships()
148185
{
149186
m_attemptToResolveOutOfOrderRelationships = true;
150187
for (Relationships relationships : m_relationships.values()) {

fflib/src/classes/fflib_SObjectUnitOfWorkTest.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ private with sharing class fflib_SObjectUnitOfWorkTest
7676
Account.SObjectType
7777
};
7878

79-
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(dependencyOrder)
80-
.attemptToResolveOutOfOrderRelationships();
79+
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(dependencyOrder, true);
8180
List<Account> accounts = new List<Account>();
8281
List<Contact> contacts = new List<Contact>();
8382
for(Integer i=0; i<10; i++)

0 commit comments

Comments
 (0)