@@ -874,8 +874,10 @@ public virtual class fflib_SObjectUnitOfWork
874
874
// Resolve relationships
875
875
for (IRelationship relationship : m_relationships )
876
876
{
877
- // relationship.Record.put(relationship.RelatedToField, relationship.RelatedTo.Id);
878
- relationship .resolve ();
877
+ if (! relationship .isResolved ())
878
+ {
879
+ relationship .resolve ();
880
+ }
879
881
}
880
882
881
883
}
@@ -938,6 +940,7 @@ public virtual class fflib_SObjectUnitOfWork
938
940
private interface IRelationship
939
941
{
940
942
void resolve ();
943
+ Boolean isResolved ();
941
944
}
942
945
943
946
private class RelationshipByExternalId implements IRelationship
@@ -955,6 +958,12 @@ public virtual class fflib_SObjectUnitOfWork
955
958
relationshipObject .put ( ExternalIdField .getDescribe ().getName (), this .ExternalId );
956
959
this .Record .putSObject ( this .RelationshipName , relationshipObject );
957
960
}
961
+
962
+
963
+ public Boolean isResolved ()
964
+ {
965
+ return this .Record .getSObject ( this .RelationshipName ) != null ;
966
+ }
958
967
}
959
968
960
969
private class Relationship implements IRelationship
@@ -964,8 +973,16 @@ public virtual class fflib_SObjectUnitOfWork
964
973
public SObject RelatedTo ;
965
974
966
975
public void resolve ()
976
+ {
977
+ if (String .isNotBlank (this .RelatedTo .Id ))
978
+ {
979
+ this .Record .put ( this .RelatedToField , this .RelatedTo .Id );
980
+ }
981
+ }
982
+
983
+ public Boolean isResolved ()
967
984
{
968
- this .Record .put ( this .RelatedToField , this .RelatedTo .Id ) ;
985
+ return String . isNotBlank ( this .RelatedTo . Id ) && this . Record .get ( this .RelatedToField ) == this .RelatedTo .Id ;
969
986
}
970
987
}
971
988
@@ -978,6 +995,11 @@ public virtual class fflib_SObjectUnitOfWork
978
995
{
979
996
this .email .setWhatId ( this .relatedTo .Id );
980
997
}
998
+
999
+ public Boolean isResolved ()
1000
+ {
1001
+ return String .isNotBlank ( this .RelatedTo .Id ) && this .email .getWhatId () == this .RelatedTo .Id ;
1002
+ }
981
1003
}
982
1004
983
1005
/**
0 commit comments