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
RobinWRobinW 

Custom Clone functionality redirecting to standard Edit page: Cancel button overwrite?

Hi All,

DId not find a similar question in the past so here it goes:
We have created a custom clone functionality. What this does is clone the record, empty some fields, update the parents, and then inserts the record in the database. Afterwards the page is redirected to the edit page of the record.

However, the standard Salesforce Edit detail record page has a cancel button. This cancel button just directs to the ?retURL paramters. So it will go back the to detail view. 

Because we performed the clone and we needed to insert this cloned record into the DB before redirecting to the Edit page, the record will not be 'cancelled' in the way of cancellation the entire clone. So the record must be deleted again.

Is there a way to capture the Cancel event? Or to redirect the page to the edit detail view of the record without inserting it into the DB? So then the user can still Click on Save and we have the requisted functionality. 

Thanks,
Robin 
JeffreyStevensJeffreyStevens
Would like to know the answer on this also.
kevin lamkevin lam
Have you tried using the cancelURL parameter?
RobinWRobinW
Hi Kevin,

What do you mean with cancelURL parameter? 
meerameera
I hope you have a VF page associated with your clone button. So when you redirect to the edit page after saving record, add cancel url also. Something like below:

cancelurlString = '/apex/vfclone?action=recorddel&delrecid='+clonedrecid;


Then in the edit page vavigation url append this cancel url also like below:


redirecturl = redirecturl+'&cancelURL='+cancelurlString;


So when the cancel button is clicked from edit page ypu will be redirected to the VF page and check for the action and based on that you can delete.

FlorSFFlorSF
Salesforce standard Clone doesn't save the record in the database until you hit Save. If I understood right, you want to go to a page where you can edit or cancel the cloned record, so I think you should build a new custom page and controller for the cloned record edit page, where you do all this: "What this does is clone the record, empty some fields, update the parents" in the costructor and move your functionality of inserting the record in the database to a Save button action. 

So your Clone button will look something like: <a href="apex/myClonedRecordEditPage?id={!recordToClone.Id}">

Your myClonedRecordEditPageController:
myClonedRecordEditPageController(ApexPages.standardController c){
  myObject__c objToClone = (myObject__c)c.getRecord();
  myObject__c clonedObj = objToClone;
  //make your modifications to clonedObj..
}

public PageReference mySave(){
   insert clonedObj;
   return Page.OtherPage;
}
and your myClonedRecordEditPage vf page something like:
<apex:page standardController="myObject__c" extensions="myClonedRecordEditPageController" ">

  <apex:commandButton action="{!mySave}" />
  <apex:commandButton action="{!cancel}" /> <!-- this will take you your original record -->

  <apex:inputField value="{clonedObj.field1}" />
  <!-- .. and all the other fields to edit -->

</apex:page>



kevin lamkevin lam
Have a look at this:
http://raydehler.com/cloud/clod/salesforce-url-hacking-basics-with-returl-saveurl-and-cancelurl.html
RobinWRobinW
Hi FlorSF, creating a new VF Page is not an option. As we cannot leverage the usage of Page Layouts. We would like to overcome creating 'static' (VF) pages.

Meera, thanks for your replace! I'm going to give this approach a go. Will let you know if this has worked or not!

Thanks,
Robin 


meerameera
Sure Robin. Please let me know if this worked.
JennyK5JennyK5
Hi Robin,
I am facing the same issue, were you able to find the solution? if so, would you mind sharing it?

Thanks
Ridhi AgarwalRidhi Agarwal
Hi Robin,
Even I am also facing exactly same issue. On click of cancel its going to parent record which is fine but record is getting cloned. Please help if u have got the solution for this.