Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloaded method for register dirty with relationships #400

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wimvelzeboer
Copy link
Contributor

@wimvelzeboer wimvelzeboer commented Mar 16, 2022

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

Copy link
Contributor

@daveespo daveespo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @daveespo and @wimvelzeboer)


sfdx-source/apex-common/main/classes/fflib_SObjectUnitOfWork.cls, line 291 at r1 (raw file):

	 * @param relatedToParentRecord A SObject instance of the parent record (should also be registered as new separately)
	 **/
	public void registerNew(List<SObject> records, Schema.SObjectField relatedToParentField, SObject relatedToParentRecord)

@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?

Routes other registerNew methods to the bulkified method overload.
@wimvelzeboer
Copy link
Contributor Author

@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.

Copy link
Contributor

@daveespo daveespo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @daveespo and @wimvelzeboer)


sfdx-source/apex-common/main/classes/fflib_SObjectUnitOfWork.cls, line 291 at r1 (raw file):

Previously, daveespo (David Esposito) wrote…

@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?

@wimvelzeboer 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

@wimvelzeboer
Copy link
Contributor Author

wimvelzeboer commented Apr 7, 2022

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.

Add bulk by default to registerNew & registerDirty
Increased unit-test coverage with using bulk
Use Custom Labels for exception messages
@wimvelzeboer wimvelzeboer force-pushed the feature/UnitOfWorkBulkRelationships branch from 4f5773a to 43be47f Compare April 7, 2022 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants