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
sfdc developer 1056sfdc developer 1056 

how to clone the case through apex

I want to create the custom clone button on case layout through apex. Can anyone help me on this
PriyaPriya (Salesforce Developers) 
Hi 

Kindly go through the below link to create the clone functionality :- 
https://www.brcline.com/blog/clone-sobject-salesforce
 

Please mark it as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan


 
Suraj Tripathi 47Suraj Tripathi 47
Hi 
 
case cas = [SELECT Origin, accountid FROM Case LIMIT 1];

Case Copy = cas.clone(false, false, false, false);

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

 
sfdc developer 1056sfdc developer 1056
Hi Suraj,
Thanks for the response. Yes it worked but i want to put the reference of the case number in the parent case field in the cloned case. 
Suraj Tripathi 47Suraj Tripathi 47
Hi,
 
case cas = [SELECT Origin,id, accountid,CaseNumber FROM Case LIMIT 1];

Case copy = cas.clone(false, false, false, false);
copy.parentCaseNumber__c=cas.CaseNumber;//parent case number field
update copy;
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer.