You need to sign in to do that
Don't have an account?
JP Blonshine
Clone with Children
I need a pice of code to drop into a button. I am struggling to correctly build this. I need to put a button on a custom object that will clone the record it is on and all the detail records in a related list.
Can someone please assist me.
Example:
Patient__c related list Patient Records__c
It is a template that I would like to use over and over.
Thank you for any help you can provide
The easiest way that I can think of to do that is to use an apex class for the cloning and call it from a custom button. There are a couple of methods to accomplish that. Here are some links:
http://salesforcesource.blogspot.com/2009/06/triggering-apex-method-with-custom.html
http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/
In your class you can get the ID of the calling record, which is the master Record and use that the get the entire record in an SObject and then use the clone() method to call it. Then use the ID to query the child object and interate through the returned list cloning each record as you go.
http://sfdc.arrowpointe.com/2011/03/28/cloning-records-in-apex/
Hope this helps you, if you have any questions let me know.