apex-enterprise-patterns / fflib-apex-common

Common Apex Library supporting Apex Enterprise Patterns and much more!
BSD 3-Clause "New" or "Revised" License
903 stars 514 forks source link

Add overloaded method for register dirty with relationships #400

Open wimvelzeboer opened 2 years ago

wimvelzeboer commented 2 years ago

With this change we can link multiple records to the same parent record.

fflib_ISObjectUnitOfWork unitOfWork = Application.UnitOfWork.newInstance();
Account accountRecord = new Account(Name = 'Test');
unitOfWork.registerNew(accountRecord);

List<Contact> contactRecords = new List<Contact>
{
  new Contact(Lastname = 'Smith'),
  new Contact(LastName = 'Janssen')
};

unitOfWork.registerNew(contactRecords, Contact.AccountId, accountRecord);
unitOfWork.commitWork();

This change is Reviewable

wimvelzeboer commented 2 years ago

@wimvelzeboer - the implementation of the new 'overloaded' versions of registerNew and registerDirty are not DRY -- there is too much code duplicated between the legacy versions of those methods and the new ones you are proposing here. Can you delegate from the single record versions to the new bulk version?

Yes, I see your point @daveespo. I now routed all the registerNew method overloads to the single bulk method.

wimvelzeboer commented 2 years ago

I see that you routed the legacy registerNew methods into the new bulkified one. But you didn't address the registerDirty duplicated code -- can you do the same treatment to those methods?

Also, while you probably didn't create any reductions in code coverage with this change, you don't have any tests to exercise an invocation of the bulkified method (passing in more than on SObject instance) so please add those

@daveespo I now added bulk by default, and increased the unit-test coverage with bulk test methods.

I also added protected method, which avoid duplicated checks. For example. in the registerDirty method with relationships it previously check for non-event and supported SObjectTypes in registerDirty and then again in registerRelationship.