Replies: 1 comment 2 replies
-
Hi @NMoore42 Good post and good questions. In short, yes, what you have proposed here is about as good as you can make self-referencing SObject relationship inserts. Your example uses the relatively new User Mode to enforce CRUD/FLS (optionally) which would've historically been implemented via one of the methods discussed in past threads via an IDML implementation. (i.e. you probably would've wanted to use the same IDML implementation as your SOUOW so that the insert operation funneled through the same business logic as the SOUOW.commitWork()) There are the lifecycle 'hooks' such as As I'm sure you can see, there is no general purpose way to support self-referencing relationships. Your case supports parent/child but would break down for grandchild, great-grandchild, etc. Or if there were multiple parents (i.e. a lookup to both a 'mother' and 'father' that needed to be populated on the child). As such, we have no plans to try to build this as a native feature into SOUOW. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been running into the documented limitation of
registerNew(record, field, parent)
not supporting self-referencing relationships (i.e., child records that point to parent records of the same SObject type).To work around this, I implemented a helper called
SelfReferenceWork
that uses theIDoWork
interface to:commitWork()
inserts the parentsBasic usage looks like this:
Here is my SelfReferenceWork Class:
Questions:
Beta Was this translation helpful? Give feedback.
All reactions