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
Arpit Jain92Arpit Jain92 

Clone records after click on custom button on vf

Hi,

I am creating a vf page on which i need to show account,opportunity and opportunity contact role with a checkbox and a custom button(Clone). I need to clone all the selected records after click on this button.

I am new to Salesforce and have worked on this functionality for a long time. I would really appreciate your help on this functionaly. 
 
Best Answer chosen by Arpit Jain92
VineetKumarVineetKumar
Check the salesforce provided clone method of the sObject class.
Try usign this, it will help you in making your code less complex and also reduce the number of lines of codes.

Reference :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

All Answers

AshokaAshoka
Hi Arpit,

This cloning functionality can be achieved by writing a javascript for this custom button.

As an example lets create a custom button "Clone" that will clone the record.

Simply override your custom button "Clone" with the following java script and you will have your custom Clone button that functions exactly like standard clone button. 

On cliking on your checkbox get your record id.Put your id in the js code.  

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
window.parent.location.href="/{!recordId}/e?&clone=1&retURL=/{!Account.Id}";

retUrl specifies the location where you want to be on press of back button. 

Thanks 
Ashoka
Arpit Jain92Arpit Jain92
Hi Ashoka,

Thank You. 

But I need to do this using wrapper class. Could you please tell me how to resolve this via wrapper.

Ragrds,
Arpit
VineetKumarVineetKumar
Check the salesforce provided clone method of the sObject class.
Try usign this, it will help you in making your code less complex and also reduce the number of lines of codes.

Reference :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm
This was selected as the best answer