Is your feature request related to a problem? Please describe.
Currently, Kahn’s dependency graph is built between SObjectTypes.
The problem occurs when records of the same SObjectType depend on each other.
Describe the solution you'd like
DML Lib should intelligently build the dependency graph and split DML operations when necessary, while still keeping the number of DML statements as low as possible.
Account parentAccount = new Account(Name = 'Test Parent');
Account myAccount = new Account(Name = 'My Account');
new DML()
.toInsert(parentAccount)
.toInsert(DML.Record(myAccount).withRelationship(Account.ParentId, parentAccount))
.commitWork();
In this case, two DML operations should be executed.
Additional context
It works in FFLib, but in an inefficient way.
Account parentAccount = new Account(Name = 'Test Parent');
Account myAccount = new Account(Name = 'My Account');
Account myAccount2 = new Account(Name = 'My Account 2');
Account myAccount3 = new Account(Name = 'My Account 3');
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new List<Schema.SObjectType> { Account.SObjectType, Contact.SObjectType });
uow.registerNew(parentAccount);
uow.registerNew(myAccount, Account.ParentId, parentAccount);
uow.registerNew(myAccount2, Account.ParentId, parentAccount);
uow.registerNew(myAccount3, Account.ParentId, parentAccount);
uow.commitWork();
In this case, 4 DML operations are executed, while only 2 should be required.
Is your feature request related to a problem? Please describe.
Currently, Kahn’s dependency graph is built between
SObjectTypes.The problem occurs when records of the same
SObjectTypedepend on each other.Describe the solution you'd like
DML Lib should intelligently build the dependency graph and split DML operations when necessary, while still keeping the number of DML statements as low as possible.
In this case, two DML operations should be executed.
Additional context
It works in FFLib, but in an inefficient way.
In this case, 4 DML operations are executed, while only 2 should be required.