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

Clone Opportunity With Products

Currently I use an override for my opportunity clone, this line being a subset of it.
var redirectURL = "{!UrlFor($Action.Opportunity.Clone,Opportunity.Id,[retURL = $Request.retURL],true)}";
Is there any way I can set it to clone with OpportunityLineItems as well?
I'm curious to see what you end up doing here as I am thinking of doing a similar mod to our clone.  Would it work if you used the "retURL" to direct the user to an s-control?  This way the s-control would run after the clone occurs and it could then copy the line items from the original record to the new record.  What do you think?

try appending the following parameter it works really well


haha... too right for the line items.  I ended up coming up with a pretty slick way to manage cloning where I display a custom "clone options" menu.  The user is then sent to the traditional clone page (and yes, cloneli argument in URL is used for that particular option)... and then after the clone takes place apex code copies over other info based on the selected options (i.e. child objects).  The coolest part is a new opp field labeled "Cloned From" which is a lookup field which links back to the original opportunity.  Lastly, a completed task is added to the original opp documenting the date and time it was cloned.
Michael, do you have the code for this? I am trying to create a clone of a custom object based on an updated field. I also have the option of using a button that mimics the cloning function in Salesforce. Basically, I want to clone the record in the object and change a field or two. Having the clone history would be great. Would you be willing to share your code with me?
here is the code we used in a custom button. very simple and might not do what you want it, however it helped us create renewal opps and change a few fields.

    {!URLFOR($Action.Opportunity.Clone,  Opportunity.Id,
opp9= text(day( Opportunity.Right_of_First_Refusal_Date__c )) +"/" + text(month( Opportunity.Right_of_First_Refusal_Date__c )) +"/" + text(year( Opportunity.Right_of_First_Refusal_Date__c )),
opp5="Banner Ad Local Renewal",
opp3= Opportunity.Name + " - RNWL",


&00N20000001MusY={!text(day( Opportunity.Campaign_End_Date__c+1 )) +"/" + text(month( Opportunity.Campaign_End_Date__c +1)) +"/" + text(year( Opportunity.Campaign_End_Date__c +1))}


What if there are several Opportunity record types? How to add that record type information to URLFOR code?

If I would like to clone a Opportunity to another and change record type while cloning??


Can you help me with this one?



Is there any way to get the newly cloned opportunity to automatically save so that after clicking the link or button the user can be brought back to another the Account page for example? 


cloning the record type can be done simply by adding the RecordType parameter to the url string:






Hi tigerpower


its a good question. i assume you have checked the html source on the edit form and that there is no hidden field for the record type.


we never needed to consider it because our record types were driven by values in a list field. we used to workflow rules with a field update action to change the record type.


So if you had 3 record types called blue green and red, then create another list field called type and had the same 3 values you could drive the record type from your type field.

 your new type field should be able to set using the urlfor function.


not the cleanest i know but will work :)

Message Edited by vitek on 03-15-2009 02:32 AM
oops didnt see sgoremas response... did it work? be nice if it did :)

Hey guys,

I've tried the to add record type to URLFOR code this way too:


It gives no syntax error while saving the code, but it does not change the record type. I have been trying out several different ways to solve the record type question, none of them working.


Vitek, Thanks for the suggestion. I'll try it out. And what you mean is that I should have another picklist field with the very same picklist values, that I already have (Opportunity type with those three record types)? And then by using a workflow rule change the record type?! By the way, I've also tried to change record type with workflow, but it only changes the picklist value, not the actual record type (and the page layout).


I've changed record types this way several times:


and it's working fine. This time I have to able to get product line items copied with the opportunity too, and as far as I know I can't get them with that solution.


Hmm. The answer has to be simple?! It always is...



Best Regards,



you can deinfitely update the opportunity record type in the field update from a workflow rule.


also have you tried appending the parameter cloneli=1


so might look like this








Yes, I've also tried it with cloneli=1.




This gaves no error messages while saving, and it does change the record type. But it doesn't clone the product line items to the target Opportunity.





i just tried this and it worked for me.


The id 006200000071Erk is the opportunity that you want to clone




Hey Vitek,

thanks for helping me out, but that solution would work only for one specific Opportunity (006200000071Erk). I think that I should be able to add the source Opportunity record type 01220000000DX9M instead of that, but it's not possible.

My source Opportunity (with the detail page button) record type  is

01220000000DX9M and the target Opportunity record type is 



This troubles me. :smileyindifferent:


Best Regards,


Message Edited by TigerPower on 03-16-2009 10:35 AM

Hey tp, i really think it should work for you. you are so close


on the opportunity create a detail link or button

content source = url


paste the following formula. After you click this link you should have 1. an oportunity open in edit mode 2. cloned from the one you are on 3. in the new record type . When you press save you should see the products in there as well.


{!URLFOR($Action.Opportunity.Clone,  Opportunity.Id,




i hope this works


Well, I had Opportunity in edit mode and when saving cloned with products, but not any record type changes.

The code is this

{!URLFOR($Action.Opportunity.Clone, Opportunity.Id,


And when cloning the source opportunity by pushing the detail page button,

the browser address bar looks like this:


I really can't find the reason why the record type is not changing with this. The search goes on...




that is really wierd... something is telling me that you should double check that you got the recordtype correct.


mine generated the following and worked. the recordtype changes correctly




I have triple checked, believe me :smileytongue:


I've also checked record types, page layout assignements... there seems not to be any errors. But. No record type changes with the button.


If I add opp5="Offer" (which is one of the type picklist values), it changes the picklist value when cloneing the Opportunity. But it doesn't change the actual Record type, because page layout doesn't change.


I need a break!

And thanks again vitek! 



no sweat :)

i would make sure that the user you are testing with has permissions to this record type (the one you are trying to change it to) it possible they don't?


Yeah, permissions is a good point too. But I checked that too.

Only thing that is "different" from the usual, is that we have also Sales Processes defined with Stage standard field. Different record types have different Stage values. But I guess that shouldn't prevent record type selection with URLFOR.