I have a parent-child relationship in which i need to change the Child's Parent record.
Basically everytime there is a change in SAP salesforce generates a brand NEW record, BUT the new record and previous old record share the same SAP document number. IE they are for the same thing except one record gets a status change to inactive and the other to active. The reason we simply don't update the current record is so we can track a history of changes that are made.
Think of it this way, theres an automated trigger that generates opportunity records EVERY TIME new data comes in from SAP, but they are the SAME 'opportunity' only an updated version. The reason we simply don't update the current record is so we can track a history of changes that are made. IE any change that happens in SAP will generate a new record in salesforce.
Now that i explained that twice i'm going into part two.
So each time a new record is generated the changes from the previous record to the new record are recorded in a child object record. But lets say there's 50 (for the same SAP document) records generated because over time there have been 50 changes in SAP. The problem becomes is each time the parent object record is generated only the changes from the previous record to the new record are listed in the child object record.
Now what i want to do is take all of the child objects and parent it to the latest parent object record. So if i have 50 parent records and 49 child records there will be 49 parent records with a status of 'inactive' and one record listed as 'active' and they share the same SAP doc number. So how do i get the 49 child records reparented to the 1 parent record that is listed as active.
obviously it'll need to be a trigger/class but i can't even begin to think of how the reparenting process works