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
Ankit Garg 117Ankit Garg 117 

Copy custom object also while cloning the opportunity

Hi,

I have a custom object called ''Banners'' on Opportuities. When users clone the opportunity, I want this custom object ''Banners'' associated witht he opportunity to be cloned as well. Please advise.

Thanks,
AbhishekAbhishek (Salesforce Developers) 
trigger CloneOpp on Opportunity (after update){
    
    Custom_Object__c[] ls=new Custom_Object__c[]{};
        for(Opportunity o: trigger.new){
            Custom_Object__c obj=new Custom_Object__c();
            //Assign whichever values you want to clone to the fields of your custom object, for example:
            //obj.name=o.name;
            
            ls.add(obj);
        }
    insert ls;
}

You can try the code snippet and have to make changes based on your requirement.

For More look at the Url:- https://developer.salesforce.com/forums/?id=9060G0000005cUUQAY


Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
Ankit Garg 117Ankit Garg 117
Hey Abhishek,

Thanks for the response. I am getting an error while creating a new opportunity. I have almost zero expericince with coding. Could you please help me with the code? This would really help me. Below is the more information about my custom object and hope it helps.

- Custom Object Name (which I want to be associated when to an opportunity when a user clones the opportunity  - Banners
- Fields to CopyBanner Name, HS_Specialty, Full Price, Total Price incl GST, Discount Price


Thanks Again :)
Ankit Garg 117Ankit Garg 117
Hi Abhishek,

This is not working. I want to copy the custom object information when cloning the existing opportuniy. Please help.