Skip to content

Commit

Permalink
Avoid code duplication
Browse files Browse the repository at this point in the history
Routes other registerNew methods to the bulkified method overload.
  • Loading branch information
wimvelzeboer committed Apr 6, 2022
1 parent f2553b0 commit f7aa2bb
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions sfdx-source/apex-common/main/classes/fflib_SObjectUnitOfWork.cls
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ public virtual class fflib_SObjectUnitOfWork
**/
public void registerNew(List<SObject> records)
{
for (SObject record : records)
{
registerNew(record, null, null);
}
registerNew(records, null, null);
}

/**
Expand All @@ -268,16 +265,7 @@ public virtual class fflib_SObjectUnitOfWork
**/
public void registerNew(SObject record, Schema.SObjectField relatedToParentField, SObject relatedToParentRecord)
{
if (record.Id != null)
throw new UnitOfWorkException('Only new records can be registered as new');
String sObjectType = record.getSObjectType().getDescribe().getName();

assertForNonEventSObjectType(sObjectType);
assertForSupportedSObjectType(m_newListByType, sObjectType);

m_newListByType.get(sObjectType).add(record);
if (relatedToParentRecord!=null && relatedToParentField!=null)
registerRelationship(record, relatedToParentField, relatedToParentRecord);
registerNew(new List<SObject> {record}, relatedToParentField, relatedToParentRecord);
}

/**
Expand Down

0 comments on commit f7aa2bb

Please sign in to comment.