`fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(MY_SOBJECTS, mockDML);
Account parent = new Account(Name = 'Parent');
Account child = new Account(Name = 'Child');
uow.registerNew(parent);
uow.registerNew(child);
uow.registerRelationship(child, Account.ParentId, Parent);
uow.commitWork();
child = [SELECT ParentId FROM Account WHERE Id =:child.Id];
Assert.isNotNull(child.ParentId);
Assert.areEqual(parentId, child.ParentId);
`
Expected behaviour is that this should pass, but it doesn't. This code might need to be fixed, I'm typing this freely. The solution we found is through an extension class to:
How to recreate:
`fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(MY_SOBJECTS, mockDML);
Account parent = new Account(Name = 'Parent'); Account child = new Account(Name = 'Child'); uow.registerNew(parent); uow.registerNew(child); uow.registerRelationship(child, Account.ParentId, Parent); uow.commitWork();
child = [SELECT ParentId FROM Account WHERE Id =:child.Id]; Assert.isNotNull(child.ParentId); Assert.areEqual(parentId, child.ParentId); `
Expected behaviour is that this should pass, but it doesn't. This code might need to be fixed, I'm typing this freely. The solution we found is through an extension class to:
` public void registerRelationship(SObject record, Schema.SObjectField relatedToField, SObject relatedTo){ if (record.Id == null && relatedTo.Id == null && record.getSObjectType() == relatedTo.getSObjectType()){ record.Id = fflib_IDGenerator.generate(record.getSObjectType()); uow.registerRelationship(record, relatedToField, relatedTo); uow.registerDirty(record); record.Id = null; }else{ uow.registerRelationship(record, relatedToField, relatedTo); } }
`
I think it would make a nice addition to the framework