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
karthik karthikkarthik karthik 

how to clone parent record using relatedlist custom button

I've Two objects Case(Parent) & CaseDetail(child) am used lookup relationship here, my requirement is in case object relatedlist i've CaseDetail custom button if click on that button i want to clone some fields values from parent record and same values to display in child object record.
once i clone parent field values is it possible to change those field values in future.
Example: I've "state" picklist field in both objects, in parent record "state" field picklist value is "new" if i click on custom button i'll get same picklist value in child record also after  some other time i need to change that picklist value from "new" to "closed" in child record.

Is the whole scenario is possible my thougt is using visualforce is possible.
can anyone pls send some source code .
Thanks in Advance.
Suneel#8Suneel#8
You can use similar code as below to clone Object data in your controller class
        Id idy=ApexPages.CurrentPage().getParameters().get('id');
        Opportunity oppty=[select name,stageName,CloseDate from Opportunity where id= :idy];
        Opportunity o=new Opportunity();
        o.name=oppty.name;
        o.stageName=oppty.stageName;
        o.closeDate=oppty.closeDate;
        insert o;
Suneel#8Suneel#8
You can also use clone method to do the same
        Opportunity o=oppty.clone(false,false,false,false);
        insert o;