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

Opportunity Cloning

I have working apex code to clone specific fields on an opportunity and opportunity line items.  I am now being asked to clone the opportunity, keeping it in edit mode, but changing the record type based on the name of the opportunity (before it opens in edit mode).  I am at a loss as to how to do this.  Would it just be an "if Opportunity Name contains blah blah, then record type id ='special rt' otherwise standard record type?


In addition (although I have not seen this happen), users claim that if they click on the clone button and then cancel instead of save, the cloned opportunity is kept anyway.  Any thoughts or ideas about this is appreciated!





Ritesh AswaneyRitesh Aswaney

If it is a straight copy of fields, then you could tweak the vanilla clone functionality that is available out of the box in salesforce.


for eg, for cloning contracts, 

Create a Custom button with a URL source

i.e. I got the URL by hitting the Clone button on a contract record, and just added the &RecordType parameter to specify the record type.


To translate the record type based on the Name, you could set up a custom setting to map the Opp name -> Record Type.

Use a Hierarchical custom setting  and then the custom button URL would be{!$Setup.Test__c.Sales__c}&retURL=%2F800C0000001DevA


where Test__c is the custom setting. You define a field for each type of Opportunity Name you want to Map.


To Save the clone opp on Cancel , you'd need to override the default Cancel Button with a Custom button which invokes the Save Action.