function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vaibhab ShahVaibhab Shah 

Reparenting records | Complex Trigger

Hi,

I have a custom object which has 2 fields:
1. Immediate Parent (Self Relationship)
2. Ancestor

Requirement given below with scenarios:
Created a record 1 --> here Immediate Parent and Ancestor is blank.
Record 2 --> Immediate Parent is record 1 and Ancestor is Record 1
Record 3 --> Immediate Parent is record 2 and Ancestor is Record 1
Record 4 --> Immediate Parent is record 3 and Ancestor is Record 1

There is one more record say Record 5 (Immediate Parent and Ancestor is blank).

Now I change the immediate parent of 2 to 5 so the outcome should come like:
Record 2 --> Immediate Parent is record 5 and Ancestor is Record 5
Record 3 --> Immediate Parent is record 2 and Ancestor is Record 5
Record 4 --> Immediate Parent is record 3 and Ancestor is Record 5

How to acheive this in trigger?

Thanks,
Vai
Christan G 4Christan G 4
Before using code, please note that you can create records with the use of a process builder. I am not really following the requirement above. Please elaborate more on the conditions for when these events should occur.