I wonder if the insert of child records with a self lookup field populated can be done as one insert job ?


Question:

I wonder if the insert of child records with a self lookup field populated can be done as one insert job ?

The use case for this is when there is a logic is being triggered after insert (trigger or flow), that is dependent on a record inserted with or without the self lookup field populated. In my tests, I see that the after insert logic treats the records inserted as they don't have the self lookup field populated.


Answer:

It's impossible to insert child records with self-reference parent lookup fields pre-populated.

The reason is that sometimes you don't have ids of the target parent records in advance, since these can be from the inserted child records themselves (circular reference).

So the Plugin always performs 2 actions for self-referenced objects:

  • Insertion of all records with null value in the self-reference field.
  • Update of all self-reference fields with parent values which are already exist.
Last updated on 29th Jan 2023