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

What is the best approach to clone a standard object ?

Good day, 


I would like to clone Quote record and by having a button "New Clone", which will doing exactly what is current "clone" button doing, but i want to pass in the previous Quote id as value of a new field in new cloning page.


May i know what is the best way to do it ?


Thanks in advance !


Is this going to be a button on the standard record view page, or a button on a visualforce page?


If the former, you can create a custom button that redirects to a Visualforce page with the standard Quote controller.  This can retrieve the Quote sobject from the standard controller, execute the clone method to get a cloned version, and then write the id of the original into the field of the new record, all in the constructor.  Then the cloned object is available for editing.


Thanks Bob, it expecting an override button of "Clone" from standard page.


Would it be possible if i make the field that received original Quote id as read only or hidden on VF page? I recall using URL hack the field will be required to be editable.


If you are using Visualforce with an extension or custom controller, you don't need to resort to the URL hack, simply pass the id as a parameter to the page.


In the controller constructor, you can then retrieve the id from the page, retrieve the details of the Quote and then clone it. As long as your inputfields on the page refer to the cloned entity and not the original entity, you can expose as much or as little as you want.  


If you do have to use the URL hack, then you will have to allow editing of the id I'm afraid.