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
surya prasad G Asurya prasad G A 

How to clone the record without related list in salesforce

Hi,

I have custom object with standard clone button that is cloning with its case related list. How to exclude the case related list when cloning the record.
Can you please suggest?

Thanks,
Prasad.
Deepak Pandey 13Deepak Pandey 13
Hi surya prasad G A,
You can create a custom button call your apex class (which will clone of Sobject) and show this to on detail page.
surya prasad G Asurya prasad G A
Hi Deepak,

Do you have any code for excluding related list when cloning the record?

Thanks,
Prasad.
Deepak Pandey 13Deepak Pandey 13
Sorry i have done with apex trigger So. But Apex code like  -
Example of Lead object record
public class cloneSobject 
{
    public static string cloneSobject(String id)
    {
    string returnMsg = '';
    
    List<Lead> lstlead = [select id,Name from Lead where id in: id];
    lead objLead = new lead();
    if(lstlead.size()>0)
        objLead =lstlead[0].clone();
    if(objLead != null)    
        insert objLead;
    
    return returnMsg;
    }
}