Skip to content

What's the current state of reflective lookups in Unit of Work? #59

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

Closed
loganm opened this issue Jul 2, 2015 · 7 comments
Closed

What's the current state of reflective lookups in Unit of Work? #59

loganm opened this issue Jul 2, 2015 · 7 comments

Comments

@loganm
Copy link
Contributor

loganm commented Jul 2, 2015

I've read that it's not handled yet. Is that still the case? Any hacks to get around it?

@loganm
Copy link
Contributor Author

loganm commented Jul 2, 2015

Looks like it doesn't, as per the following unit test. I'll have a play and see if I can make something work.

I'm thinking, because reflective lookups can't be required, the UnitOfWork could do two DML passes on those records. One to insert them and get Ids, and another to backfill the reflective lookups and update if required.

@IsTest
private static void reflectiveLookups()
{
    fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
    Product_Category__c productCategory1 = TestObjectFactory.createProductCategory( uow );
    Product_Category__c productCategory2 = TestObjectFactory.createProductCategory( uow, productCategory1 );
    Product_Category__c productCategory3 = TestObjectFactory.createProductCategory( uow, productCategory2 );
    uow.commitWork();
    productCategory1 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory1.Id];
    productCategory2 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory2.Id];
    productCategory3 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory3.Id];
    System.assertEquals(null, productCategory1.Parent_Category__c);
    System.assertEquals(productCategory1.Id, productCategory2.Parent_Category__c, 'The category should be related to a parent category');
    System.assertEquals(productCategory2.Id, productCategory3.Parent_Category__c, 'The category should be related to a parent category');
}

System.AssertException: Assertion Failed: The category should be related to a parent category: Expected: a0KO0000004aLS0MAM, Actual: null

@loganm
Copy link
Contributor Author

loganm commented Jul 2, 2015

@afawcett I've added support for reflective lookups to my fork. Can you turn this into a feature request, and I'll do a pull request for review.

@afawcett
Copy link
Contributor

afawcett commented Jul 3, 2015

It's maybe because its been quite a long week, but can you elaborate more on what a 'reflective lookup' is?

@loganm
Copy link
Contributor Author

loganm commented Jul 21, 2015

Phew, tough sprint. Finally got some head space back.

By reflective lookup, I mean a self lookup, or a self relationship. A lookup that points to the same SObjectType on which it's created.

I've patched my fflib fork to handle self lookups and it's working well. Sure there is a performance hit, but I've found doing an insert followed by an update is much friendlier than trying to chain DML inserts within an SObjectType.

@afawcett
Copy link
Contributor

Thanks @loganm, sounds interesting, looking forward to taking a look at this.

In the meantime have you seen this long standard PR from @adtennant?

#23

@loganm
Copy link
Contributor Author

loganm commented Aug 27, 2015

My solution for cyclic dependancies has been in play on my org for a while now, and hasn't spat the dummy once. So I'll open a pull request of its current state for review.

@daveespo
Copy link
Contributor

daveespo commented Jun 8, 2023

I don't know if this is still true .. please reopen with a repro case if so

@daveespo daveespo closed this as completed Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants