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

Relationship is not created if both records are of the same type and are both new #279

Open
JoelBrenstrum opened this issue Apr 16, 2020 · 1 comment

Comments

@JoelBrenstrum
Copy link

JoelBrenstrum commented Apr 16, 2020

We're currently using a much older version of fflib (~2014), We upgraded to the latest version and are experiencing this issue.

here is a simple example to repro, you will need to create an additional lookup on account.

fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();

Account a = new Account(Name= 'Test');
Account b = new Account(Name = 'Test2');
uow.registerRelationship(a, Account.Primary_Supplier__c,b);
uow.registerNew(a);
uow.registerNew(b);
uow.commitWork();

system.assert(a.Id != null);
system.assert(a.Primary_Supplier__c != null);
System.debug('SUCCESS');

2014 version we get SUCCESS
Latest version

"exceptionMessage": "System.AssertException: Assertion Failed",
"exceptionStackTrace": "AnonymousBlock: line 12, column 1"

any ideas or help would be greatly appreciated.

@nicholas-getpraxis
Copy link

I've gotten success using multiple UnitOfWorks in your same scenario, i.e. setting relationships on the same object, e.g.

//Create a UnitOfWork to handle the object relationships and dmls
fflib_SObjectUnitOfWork uow = (fflib_SObjectUnitOfWork) Application.UnitOfWork.newInstance(new List<SObjectType>{Account.SObjectType});
fflib_SObjectUnitOfWork uow2 = (fflib_SObjectUnitOfWork) Application.UnitOfWork.newInstance(new List<SObjectType>{Account.SObjectType});

//Create SObjects in memory
Account a = new Account(Name= 'Test');
Account b = new Account(Name = 'Test2');

//insert records
uow.registerNew(b);
uow2.registerNew(a, Account.Primary_Supplier__c,b);
uow.commitWork();
uow2.commitWork();

In scenarios where the SObjectTypes are different, I've been able to use one uow, but in this case, I've had to use multiple (one for each level of the same SObjectType)

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

No branches or pull requests

2 participants