+ Start a Discussion
Adnan PAdnan P 

Custom Clone button for Case to validate picklist values


I was hoping someone could provide some insight with an issue that I'm having.  I'm attempting to create a custom Clone button that will validate whether any picklist values being copied over are inactive.  If the picklist value is no longer active it would be cleared and the user would be forced to select a new value on the edit page before saving.  

The issue that I'm having is that I don't know how the take the user to the edit page of the cloned Case without inserting the Case first because I need the ID of the cloned Case for the PageReference.  The problem is that once the Case is inserted the user could click "Cancel" on the edit page assuming that the cloned Case will not be created but it has already been inserted.  Obviously, this may create junk data.

My understanding of Apex/Visualforce is limited.  Does anyone know if there's a way to land on the edit page for the cloned Case without having to insert the Case first?  I don't want to insert until the User clicks "Save" on the edit page.

Thanks in advance!!
Ajay K DubediAjay K Dubedi
Hi Adnan,
I have developed this code to clone contact so youc can change this according to your need and add a button on vf page and use cloneContact as action for that button :

public class CustomController {
ApexPages.StandardController con;
public ContactDetailControllerClass(ApexPAges.StandardController controller){
public PageReference cloneContact(){
 Contact ct = (Contact)con.getRecord();
 Contact ctCloned=new Contact();
 insert ctCloned;
 return con.edit();