+ Start a Discussion

Cant open record in edit page with same page layout, pass clone parameter and use retURL?

I have written a clone method to get the child records with the record being cloned. I had just simply hard coded the fields that can be edited during cloning. Now I am running into the problem of users wanting to see all fields for the corresponding page-layout in while cloning. So I am trying to figure how how I can clone a record into an edit page for the same page layout as the record being cloned. 


I can't figure out a way to do this.


Here is what I am trying from a custom button on a detail page.






 The "save" button on the edit page that I have no access to change sends me here...





It ignores my retURL all together. 




Thank you for any help. I'm stuck.



hi Walter,

use this idea this was helpful for me to direct to the clone  page and re-direct to the parent page.


my_URL="{!URLFOR( $Action.Opportunity.Clone, Opportunity.Id,[retURL=URLFOR($Action.Opportunity.View, Opportunity.Id)])}"+ add all thefield id's that needs to be hardcoded along with the value. the rest of the fields will contain the same value as a default clone.


at last use this line too

window.parent.location.href = my_URL;
 this line will initiate the page movement.


Hi Bharathwaj ,


Thank you for the info, I've never used that before so I am reading up on it.


 I do not think I am using this correctly yet, can you take a look?



here is what i am trying



my_URL="{!URLFOR( $Action.SFDC_Projects__c.Clone, SFDC_Projects__c.Id,[retURL='/apex/clone?pId=SFDC_Projects__c.Id'])}";window.parent.location.href = my_URL;



what happens is when i click the standard save button in the clone edit page it takes me to the standard view page for the record


when i click the standard cancel button in the same page it uses my retURL and does end up where i want the save button to take you after performing the save, but the 

record Id merge is not written correctly because i end up here when i click cancel




can you see what I am doing wrong? 


I am trying to send the user here "/apex/clone?pId={!SFDC_Projects__c.Id}" after they click "save" in the clone edit page.


Thanks again. 


This is working when i click cancel but not when i click save.



myObjId="{!SFDC_Projects__c.Id}"; my_URL= "{! URLFOR( $Action.SFDC_Projects__c.Clone, SFDC_Projects__c.Id, [retURL=URLFOR('/apex/clone', SFDC_Projects__c.Id, [pId=SFDC_Projects__c.Id])] ) }"; window.parent.location.href = my_URL;




Do I need to do this in a VF page with apex class as an extension to the SFDC_Projects__c object with an override to the standard controller save button?




I have something in place which is doing what I want, but I have a lot of steps so I wanted to post it here incase someone can offer up some suggestions for a better way to do this.




Click 'clone' button, go to clone edit page with exact same page layout as record being cloned. When you click 'save' button in the clone edit page, it sends you to my VF page '/apex/clone' which allows you to select which related child records you also want to bring over to the new cloned record.


What I am doing:


1. custom button to go to clone page, so I can pass a value for a field 'I store the id of the record that was cloned in field clonedId__c'

2. vf page to override the standard 'view' for the record

3. extension to the object for the vf page 'view' override, to handle sending the user to '/apex/clone' if clonedId__c is not null

4. the controller for '/apex/clone' gets all related records, i.e.Task, Case, Attachment, Note, Project_Comments__c, etc where their parent Id is clonedId__c, and when you save it adds these records to the new cloned record

5. I use a trigger to add a sort of audit trail of where the record was cloned from in the form of a "case comment" like custom object related to the object record being cloned "Project_Comments__c".





button to clone



 where '00NQ0000000GdVD' is the ID of the field i write the "cloned record id" to, in order to later pass that as url paramter 'pId' in the controller for my page '/apex/clone'.

after you click the standard 'save' button in the clone edit page, it sends you to the view page (now overridden), the view page is my VF page, and onload if the field "00NQ0000000GdVD / clonedId__c" is not null, it sends you to my other page '/apex/clone'.


extension for project view override



public with sharing class projectExtension { private ApexPages.StandardController controller; id projectId; string clonedId; public projectExtension(ApexPages.StandardController c) { controller = c; projectId = c.getRecord().id; getMyProject(); } void getMyProject() { for(SFDC_Projects__c p : [select clonedId__c from SFDC_Projects__c where Id = :projectId limit 1]) { clonedId = p.clonedId__c; } } public PageReference runThis() { if(clonedId!=null) { PageReference acctPage = new PageReference('/apex/clone?pId='+clonedId +'&ogId=' +projectId); acctPage.setRedirect(true); return acctPage; } return null; } }



page for project view override



<apex:page standardController="SFDC_Projects__c" extensions="projectExtension" action="{!runThis}"> <apex:detail subject="{!SFDC_Projects__c.Id}" /> </apex:page>





trigger projectTrigger on SFDC_Projects__c (after insert) { List<Project_Comment__c> projectComments = new List<Project_Comment__c>(); for (SFDC_Projects__c p1 : Trigger.new) { if(p1 != null) { projectComments.add ( new Project_Comment__c( Project__c=p1.Id, Comment__c = '[*** AUTO MESSAGE - Cloned from: ' +p1.clonedId__c +' ***]') ); } } insert projectComments; }