Each Opportunity in our Salesforce system may have zero or more related Opportunity Items which are custom objects. The relationship and use of Opportunity and Opportunity Items is like Orders and Order Items in an e-commerce system.

When an Opportunity is cloned by clicking the Clone button on the Opportunity Details page, these associated objects are not cloned.

I would like to intercept the cloning process to manually clone the Opportunity Items as well.

This must be a fairly common scenario, and I thought of implementing a trigger however, I don't know how to distinguish between a New Opportunity and a Cloned Opportunity, I've presumed that it's just a new Opportunity to the trigger.

How might I clone an Opportunity plus the related Opportunity Items. I should also add the further complication that the cloned Opportunity Items have a custom field named IsEditable__c that must be set to false on the cloned Opportunity Items.


You can override the clone action by creating your own interim visualforce page that utilises the standard controller of the opportunity sObject and write an apex extension controller to write your logic. Here is a really good answer that will get you going


You have two options really:

  1. Use a Visualforce page & Apex controller as @Bachovski has suggested.
  2. Use a Javascript button on the Opportunity detail page which calls a webservice class to clone the record, then (optionally) redirect the user to the new record.

Here is a good guide on the second approach: link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.