+ Start a Discussion
nik9000nik9000 

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?
michaelforcemichaelforce
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?
vitekvitek

try appending the following parameter it works really well

cloneli=1

michaelforcemichaelforce
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.
 
 
JeffroJeffro
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?
Thanks,
Jeff
vitekvitek
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,
[
cloneli=1,
opp11="New",
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",
opp14="",
opp10="Renewal",
opp3= Opportunity.Name + " - RNWL",

CF00N20000001O1Q3=0,
CF00N20000001O1Q3_lkid=0,
CF00N20000001O1Q3_lkold=0,
CF00N20000001O1Q3_lktp=0,
CF00N20000001O1Q3_mod=""

],
true)}
&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))}
&00N20000001Musd=""
&00N200000016FT2=""
&00N20000001LEhB=""
&00N20000001LEhQ=""
&00N20000001Musi=""
&00N20000001N6WF=""
&00N20000001N6WG=""
&00N200000017pqd=""
&00N20000001MwlN=""
&00N20000001MwlI=""
&00N20000001N6WA=""
&00N20000001N6WK=""
TigerPowerTigerPower

Hey,

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?

 

sgoremasgorema

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 page..like the Account page for example? 

 

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

 

RecordType="012300000000fdmAAA",

 

 

vitekvitek

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
vitekvitek
oops didnt see sgoremas response... did it work? be nice if it did :)
TigerPowerTigerPower

Hey guys,

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

RecordType="012300000000fdmAAA"

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:

/800/e?&RecordType=012200000009KO3 

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...

:smileyhappy: 

 

Best Regards,

TP

vitekvitek

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

/800/e?&RecordType=012200000009KO3&cloneli=1

 

 

 

 

 

TigerPowerTigerPower

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

 

/006/e?&RecordType=01220000000DX9R&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.

 

BR,

TP

vitekvitek

i just tried this and it worked for me.

 

https://emea.salesforce.com/006200000071Erk/e?clone=1&cloneli=1&RecordType=01220000000DBQU

 

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

 

 

TigerPowerTigerPower

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 

01220000000DX9R.

 

This troubles me. :smileyindifferent:

 

Best Regards,

TP

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

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,
[
cloneli=1,

RecordType=01220000000DX9R

],
true)}

 

i hope this works

TigerPowerTigerPower

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,
[
cloneli=1,
RecordType="01220000000DX9R"
],
true)}

 

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

the browser address bar looks like this:

https://emea.salesforce.com/00620000007hlO8/e?clone=1&retURL=%2Fservlet%2Fservlet.Integration%3FscontrolCaching%3D1%26lid%3D00b200000016Gjd%26eid%3D00620000007hlO8%26ic%3D1&nooverride=1&cloneli=1&RecordType=01220000000DX9R

 

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

 

TP

vitekvitek

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

https://emea.salesforce.com/006200000074ctS/e?clone=1&retURL=%2Fservlet%2Fservlet.Integration%3Flid%3D00b2000000157Js%26eid%3D006200000074ctS%26ic%3D1&nooverride=1&cloneli=1&opp11=New&RecordType=01220000000DBQU

 

 

TigerPowerTigerPower

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! 

 

TP

vitekvitek
no sweat :)
sgoremasgorema

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)..is it possible they don't?

TigerPowerTigerPower

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.

 

TP