Hi,
I have some unclarity's about cloning a record; This is the case: I have an order object and also related records (orderline, ordertyre and orderlynedetails are related (n:1) to order). In the case i clone the order record the orderlines should also be cloned but the original orderlines should be related to the old order; only the newly created orderlines should be connected to the new order. However all the related records (orderline, orderlinedetails and ordertyres are related to the newly created order!
Should i do something special so that the orginal orderline, orderlinedetails and ordertyres stay to the orginial order?
Kindly reply
How are you cloning the records?
I think that your requirement needs a Workflow action, a create new record trigger, and a data map.
Setup the create new record trigger to use your data map then setup the workflow action to run the create new record trigger.
*** Data maps support cloning of related records per your requirement. You should see the relationships that allow you to choose which should be cloned and which shouldn't at the bottom of your data map.
Hope this helps.
|
I see.
If my understanding is correct, you've already tried using a Create New Trigger + Data Map?
If not, I suggest you try that -- it would take out all this code that you have. (suggestion from my original reply).
If you have, then might I suggest that in your data map, leave the auto-number field as "Not Mapped" or "Default Value".
It might solve your +1 number issue.
Hope this helps.
If all else fails, unfortunately, I think you'd have to abandon the cloneRecord() API and use the createRecord() API.
I haven't used the cloneRecord() api myself because I've never encountered your auto-number issue when using create new record and data maps in the past.
Please confirm if you've tried Create New Record (trigger type) + Data map.
Hope this helps.
|
|
At the end of the data map that you are using, there should be some checkboxes there that indicate cloning related records (as opposed to just moving them from the order that was cloned.
Could you post a screenshot of your data map and the create new record trigger that you are using?
Thanks
|
|
Are the related lookups mapped?
I think the setting you need to change is on the three relationships.
You could probably try setting the related lookups to "not mapped" or "default value" or to blank.
I would assume that for the three lookups that are set to clone, the cloned records should be the ones that would show and not affect the originals.
Hope this helps
|
Assuming that the field is an integer or decimal field: Create a formula field.
Inside of the formula field's script, use the original value * -1 as the return value.
Then map the field in the data map instead of the original field.
That should get you what you need.
Hope that helps.
|
Ah, I see what you mean now, the change needs to happen on the children and not the parent.
1. On the child object, create a update field value trigger without any timing that changes the value that you need to change. (e.g. change qty to negative)
2. On the parent object, create a "run triggers on related records" trigger without any timing - choose your child object in the picklist. Attach this trigger to your workflow action so it runs only at the time the workflow is pressed (assuming you use a clone workflow action - if you are not, you need to be to use this method).
2.1 If you aren't using a workflow action, you need to create a trigger that iterates through all of your child record and calls runTrigger() on each on them to run the trigger in #1 (i prefer the "run triggers on related records" approach since it is more streamlined and less prone to code issues unlike this one).
Hope this helps.
|
I see what you mean. For this I would suggest that you create a hierarchy relationship on your parent object and map it in your data map. Map it so that the cloned record would be the One in the one:many relationship, this way from the parent's perspective, you can access the token of the cloned record easily.
Then call your "run trigger on related records" on the related cloned record using runTrigger() API and possibly an object script appended to your workflow action (don't forget to remove the other trigger from the workflow).
This should make the trigger run on the cloned record.
Hope that helps.
1. Put negative values in orderline (quantity etc)
2. Clone object order (which creates also orderlines (with negative values)
3. Put negative value (which reverses point 1) so we have positive values in original orderline again.
|