I need to clone a record displayed via VisualForce. Created this button which works eventually but does not open the cloned page in the proper record type:

Using either formats seems to open the object as an format and not using the VisualForce page I launched the clone button from. If I save this detail page it is then presented in the proper VisualForce page. Short of writing a method in the controller is there a practical way to do this?

<apex:commandButton value="Clone" action="{!URLFOR($Action.Account_Summary__c.Clone,Account_Summary__c.id)}"/>

<apex:commandButton value="Clone2" action="{!URLFOR($Action.Account_Summary__c.Clone,Id,[retURL=Id],true)}"/> 

This syntax opens the record in a VisualForce page but none of the field values set on the original carry over to the cloned VisualForce page.

<apex:commandButton value="Clone3x" action="{!URLFOR('/apex/PROD_UW_AccountSummary', Id, [retUrl=Id,clone='true',name=Account_Summary__c.Name, cid=Id], true)}&RecordType=0120S0000004XY4QAM" />
  • Clone is going to take you to an edit page with the parameters clone=1 and id=recordId... If you want to directly clone the record without the intermediate page, you'll need to write Apex Code.
    – sfdcfox
    Commented Sep 1, 2017 at 15:17
  • OK. Is there something on the intermediate page that I can read to un-render a large part of the page so it looks cleaner? I'll ask another question on sample apex code to create a clone.
    – rickmac
    Commented Sep 1, 2017 at 15:24
  • Looking at this intermediate page further its opened as a Force.com page and not a VisualForce page. So it does not seem possible to using rendering to hide anything. It is using the same record type as the original record. Do you think its possible to have the intermediate page open in a new record type containing just the fields I need, use a custom 'Save' button that sets the recordtype back to the original so it opens properly in VisualForce ?
    – rickmac
    Commented Sep 1, 2017 at 15:35

1 Answer 1


you may need to just add the url for the page/ add parameters to the current page like below:

<apex:page  standardController="Jurisdiction__c">
   <apex:pageBlock title="{!Jurisdiction__c.Name}" rendered="{!OR($CurrentPage.parameters.clone = 'false', $CurrentPage.parameters.clone = null)}">
       <apex:pageBlockButtons location="top">
          <apex:commandButton value="Clone" action="{!URLFOR('/apex/Test', Id, [retUrl=Id,clone='true',name=Jurisdiction__c.Name, cid=Id], true)}" />
       <apex:outputField value="{!Jurisdiction__c.Name}" />
       <apex:outputField value="{!Jurisdiction__c.Id}" />

   <apex:pageBlock rendered="{!$CurrentPage.parameters.clone='true'}">
       <apex:pageBlockSection columns="1">
           <apex:inputField value="{!Jurisdiction__c.Name}" />
           <apex:inputField value="{!Jurisdiction__c.OwnerId}" />

I just used a generic custom object here to illustrate this - you can substitute for your own object for testing but would see the below in the screens below: View Page: View Page

Clone View: Clone view

you'll notice that the URL holds the parameters you need - you can populate the fields if you want in Javascript pulling the values from the parameters

URL after clone button clicked:


  • 1
    Thanks Ronnie. I was trying to figure something similar out. I have 3 record types for the object but I think doing this will simply use the current recordtypename hosting the the clone button. I'll try this and provide an update.
    – rickmac
    Commented Sep 2, 2017 at 14:06
  • you could control the record type or even give options for that to be selected by using a Custom Metadata Type and a controller here too which would offer a little more automation to that selection or flexibility in the selection with a custom built picklist
    – Ronnie
    Commented Sep 2, 2017 at 15:32
  • Yes. I only want to keep one record type as the current version. The others are older non VF pages that will open for historical viewing. Any clone should use the same one from the parent at this point.
    – rickmac
    Commented Sep 2, 2017 at 16:06
  • just add the record typeid to the params <apex:commandButton value="Clone" action="{!URLFOR('/apex/Test', Id, [retUrl=Id,clone='true',name=Jurisdiction__c.Name, cid=Id;recordTypeId=Jurisdiction__c.RecordTypeId], true)}" /> just for example
    – Ronnie
    Commented Sep 2, 2017 at 16:07
  • 1
    I agree. The blog you mentioned has a previous article on just cloning the object / properties and not all child objects (which I don't need - christopheralunlewis.blogspot.co.uk/2011/05/… ) Also, using the $actions that shows the Sobject to the user only requires that the fields needed are on the layout page. So I'll start with that then move to the controller approach. Of course it would be great if SalesForce allowed for a VisualForce page returnURL when cloning.
    – rickmac
    Commented Sep 4, 2017 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .