@@ -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 ()) {
0 commit comments