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
Lakshmi SLakshmi S 

How to clone the record using custom detail page?

Hi Team,

I am using standard clone functionality for cloning the record. but my code override the existing record, instead of creating new record.
public PageReference doClone(){
        try{
            //con.save();
            PageReference pr = Page.HighRiskSuccessFactorsVFPage;
            pr.setRedirect(true);
            pr.getParameters().put('id',con.getId());
            return pr;
        }catch(Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
            return null;
        }
    }
Please let me know, how can we achieve this using custom functionality.

Thanks
Lakshmi.
 
Raj VakatiRaj Vakati
Try some think like below 
 
public PageReference doClone(){
        try{
            //con.save();
            PageReference pr = Page.HighRiskSuccessFactorsVFPage;
            pr.setRedirect(true);
			
			Account acc = [Select Id from Account where id =:con.getId()];
			Account clonedAcc = acc.clone(false, false, false, false);
			//insert clonedAcc ;
			
            pr.getParameters().put('id',clonedAcc.Id);
			
			
            return pr;
        }catch(Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
            return null;
        }
    }

 
Lakshmi SLakshmi S
Hi Raj,

It is not working.

Thanks
Lakshmi