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
ScriptMonkeyScriptMonkey 

Triggers/Updating Children after Contacts are Merged?

I am working with an export method that requires "flattening" of data, so my schema of children objects has a field "exportSequence" which is just an integer ordered by date.

 

I have triggers to update that order when a new child record is made, or deleted. but I just found out today that if contacts are merged, then the children record triggers do not fire. (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_merge_statements.htm)

 

I need a suggestion as to how to make the children object triggers fire (without looping) to reorder themselves based on the contact they're attached to.

 

Note: There are 5 objects all children to Contact, and I'm hoping to not have the global "reorder everything" trigger on the contact, that will reorder all five children objects when I only need to do one or two.

 

Thanks,

ScriptMonkey

MarkWaddleMarkWaddle

Hi ScriptMonkey,

 

Why do you need the additional integer field when you can just order by the date when you are exporting?

 

Mark

ScriptMonkeyScriptMonkey

Mark,

I need to export it using a tool that does not handle "iterations", it needs to lookup exact values, child record 1, child record 2, etc.

 

MarkWaddleMarkWaddle

I'm having a hard time grasping the whole problem here. Would you mind posting the existing triggers?

ScriptMonkeyScriptMonkey

I really can't without stripping out all the proprietary code.  It's really very simple though.

 

Whenever you add, or delete, any child object, the triger reorders all of that child object based on create date, then iterates through, and sets exportSequence 1, 2, 3, 4, 5, etc.

 

so if I add one between 2 and 3, it will reorder all, and 1,2,3,4 becomes 1,2,3,4,5 (with the new one being three).  If I delete 4, it will reorder back to 1,2,3,4.

 

The problem is that if I have two contacts, each with 1 and 2, and I merge them, the resulting record has children with exportSequence 1,1,2,2 instead of 1,2,3,4 because child triggers aren't run.

 

MarkWaddleMarkWaddle

Have you considered putting a trigger on the parent object as well? You could use the technique described here to prevent the child triggers from getting fired when you update their exportSequence fields.