Skip to content

Commit b2207d9

Browse files
🐛 Control multiple resolving
To mitigate creatable but not upateable fields
1 parent f5a4ca8 commit b2207d9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

sfdx-source/apex-common/main/classes/fflib_SObjectUnitOfWork.cls

+25-3
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,10 @@ public virtual class fflib_SObjectUnitOfWork
874874
// Resolve relationships
875875
for (IRelationship relationship : m_relationships)
876876
{
877-
//relationship.Record.put(relationship.RelatedToField, relationship.RelatedTo.Id);
878-
relationship.resolve();
877+
if (!relationship.isResolved())
878+
{
879+
relationship.resolve();
880+
}
879881
}
880882

881883
}
@@ -938,6 +940,7 @@ public virtual class fflib_SObjectUnitOfWork
938940
private interface IRelationship
939941
{
940942
void resolve();
943+
Boolean isResolved();
941944
}
942945

943946
private class RelationshipByExternalId implements IRelationship
@@ -955,6 +958,12 @@ public virtual class fflib_SObjectUnitOfWork
955958
relationshipObject.put( ExternalIdField.getDescribe().getName(), this.ExternalId );
956959
this.Record.putSObject( this.RelationshipName, relationshipObject );
957960
}
961+
962+
963+
public Boolean isResolved()
964+
{
965+
return this.Record.getSObject( this.RelationshipName ) != null;
966+
}
958967
}
959968

960969
private class Relationship implements IRelationship
@@ -964,8 +973,16 @@ public virtual class fflib_SObjectUnitOfWork
964973
public SObject RelatedTo;
965974

966975
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()
967984
{
968-
this.Record.put( this.RelatedToField, this.RelatedTo.Id);
985+
return String.isNotBlank( this.RelatedTo.Id ) && this.Record.get( this.RelatedToField ) == this.RelatedTo.Id;
969986
}
970987
}
971988

@@ -978,6 +995,11 @@ public virtual class fflib_SObjectUnitOfWork
978995
{
979996
this.email.setWhatId( this.relatedTo.Id );
980997
}
998+
999+
public Boolean isResolved()
1000+
{
1001+
return String.isNotBlank( this.RelatedTo.Id ) && this.email.getWhatId() == this.RelatedTo.Id;
1002+
}
9811003
}
9821004

9831005
/**

0 commit comments

Comments
 (0)