Clone with Related list
The standard clone button provided by Salesforce does not have the capability to clone the related list records. So I thought of creating a custom button which will clone the parent record along with the related list records up-to one level deep. For example, you can clone Account with Contacts or Opportunities with Quotes or any standard or custom object. This app also provides you the ability to select which object's child records you want to clone.
Code is uploaded @ GitHub Repo
Follow below steps to make it working on your Salesforce org :
1) Copy the classes and VF page from GitHub to your Salesforce org.
2) Create a button named "Clone with Related List" on the object you want to clone. I will take the example of Account.
Behavior of the button should be "Execute JavaScript" and Content Source should be "OnClick JavaScript"
3) Copy below code for the button :
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
window.open("/apex/CloneWithChildren?id={!Account.Id}&retUrl={!Account.Id}","_self");
Let us take a look at the URL parameter. I have passed Account.Id in both id and retUrl parameters. You need to pass the id of the record on which you are creating this button. For Opportunity, the code would look like below :
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
window.open("/apex/CloneWithChildren?id={!Opportunity.Id}&retUrl={!Opportunity.Id}","_self");
4) Add the button to the page layout and you are good to go.
This is how it would look like on your Salesforce org :
1) Clone with Related List Button :
2) Page to select which object's records needs to be cloned :
Code is uploaded @ GitHub Repo
Follow below steps to make it working on your Salesforce org :
1) Copy the classes and VF page from GitHub to your Salesforce org.
2) Create a button named "Clone with Related List" on the object you want to clone. I will take the example of Account.
Behavior of the button should be "Execute JavaScript" and Content Source should be "OnClick JavaScript"
3) Copy below code for the button :
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
window.open("/apex/CloneWithChildren?id={!Account.Id}&retUrl={!Account.Id}","_self");
Let us take a look at the URL parameter. I have passed Account.Id in both id and retUrl parameters. You need to pass the id of the record on which you are creating this button. For Opportunity, the code would look like below :
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
window.open("/apex/CloneWithChildren?id={!Opportunity.Id}&retUrl={!Opportunity.Id}","_self");
4) Add the button to the page layout and you are good to go.
This is how it would look like on your Salesforce org :
1) Clone with Related List Button :
2) Page to select which object's records needs to be cloned :
Comments
Post a Comment