+ Start a Discussion
DJTryingToLearnDJTryingToLearn 

I want to add logic to the Clone button that performs a field update?

Do you know? Can you help?

 

Is it possible to add logic to the Standard Clone button to update a field "Cloned?" to "Yes" on the oppty record when an oppty is cloned?

 

Any feedback or suggestions would be truly appreciated.

 

Best Answer chosen by Admin (Salesforce Developers) 
BrianWKBrianWK

DJ - I think You're close

When cloning an Opportunity I this:

https://na5.salesforce.com/0067000000KlYBa/e?clone=1&retURL=%2F0067000000KlYBa

 One way to test what this does is identify the pieces and replace them manually in the URL before creating the button.

 

for instance the character string starting with 006 is the Opportunity ID. If I go to a different Opportunity and Copy and Paste its ID over the one present in my above link... I should get the Clone edit page for the different Opportunity. Once I confirm that I understand how the URL works we can start replacing things for your button.

 

What I'll do after I identify  the different parts of the URL is start putting it together in pieces .So first the clone portion

 

https://na5.salesforce.com/{!Opportunity.id}/e?clone=1

 

Then finally the ret URL:

&retURL=%2F{!Opportunity.id}

 Try putting that whole thing together first and see if you get your clone functionality. Then you can continue to add to the URL to fill in values on that Edit Page.

 

 

All Answers

Ritesh AswaneyRitesh Aswaney

URL Rewriting is possible - a little bit of a hack, as html id's tend to be environment specific. although they will be the same on sandboxes refreshed from production.

 

You could add the 'Cloned' field to the Edit Page Layout, then figure out the html id of this field (view source and search for the label to find the id). 

 

Override the default Clone button with a custom button, set the URL to the same one as the one the standard buttons sends you to (hit Clone and copy from browser URL).

Simple add the &HTML_ID=true at the end of the URL.

 

so for eg. 

https://XXX.salesforce.com/006/e?clone=1&id=006P0000002IErS&nooverride=1&retURL=/006P0000002IErS&scontrolCaching=1&sfdc.override=1&00N20000001Pe3J=true


DJTryingToLearnDJTryingToLearn

I can see how this formula should work hard coding an id for the oppty, but if I add this as a button, do you know how to set it so that it dynamically pulls each new oppty id?  Or am I overthinking this?

Ritesh AswaneyRitesh Aswaney
You can use {!Opportunity.Id}
DJTryingToLearnDJTryingToLearn

Thank you for your patience! 

 

I'm still hitting an error:  here's what I have so far - you probably see something obvious! ?

 

https://cs4.salesforce.com/006/e?clone=1&id={!Opportunity.Id}&nooverride=1&retURL=/{!Opportunity.Id}&00N20000001Pe3J=true

 

....getting keyboard forehead! :P

Ritesh AswaneyRitesh Aswaney
Can't remember a 100% but try quotes around the formula field. So '{!Opportunity.Id}' Better still use the insert field dropdown to add the id field to the URL and see how the element is rendered. On the train so a lil constrained! :)
DJTryingToLearnDJTryingToLearn

aaaargh!  I think I've tried every variation and I need to break and come back and look at it with fresher eyes or something!  Still erroring...   Here's my latest version attempt:

 

https://cs4.salesforce.com/006/e?clone=1&id='{!Opportunity.Id}'&nooverride=1&retURL=/'{!Opportunity.Id}'&00N20000001Pe3J=true

 

 

 

BrianWKBrianWK

DJ - I think You're close

When cloning an Opportunity I this:

https://na5.salesforce.com/0067000000KlYBa/e?clone=1&retURL=%2F0067000000KlYBa

 One way to test what this does is identify the pieces and replace them manually in the URL before creating the button.

 

for instance the character string starting with 006 is the Opportunity ID. If I go to a different Opportunity and Copy and Paste its ID over the one present in my above link... I should get the Clone edit page for the different Opportunity. Once I confirm that I understand how the URL works we can start replacing things for your button.

 

What I'll do after I identify  the different parts of the URL is start putting it together in pieces .So first the clone portion

 

https://na5.salesforce.com/{!Opportunity.id}/e?clone=1

 

Then finally the ret URL:

&retURL=%2F{!Opportunity.id}

 Try putting that whole thing together first and see if you get your clone functionality. Then you can continue to add to the URL to fill in values on that Edit Page.

 

 

This was selected as the best answer
DJTryingToLearnDJTryingToLearn

:smileyvery-happy:  THANK YOU THANK YOU THANK YOU!  I FINALLY GOT IT!  I'm so excited I want to CELEBRATE! WOOO HOOO!  THANK YOU!

Ritesh AswaneyRitesh Aswaney
Awesome! Well done! Will be a good idea to post the URL that worked! Enjoy! ;)
DJTryingToLearnDJTryingToLearn

My biggest obstacle was that I was using the wrong Behavir type - so after I chose "Dispaly in existing window without sidebar or header" and Content Source = URL, here is my final formula:

 

Note - My Cloned? field is a picklist field

 

https://na3.salesforce.com/{!Opportunity.Id}/e?clone=1&retURL=%2F{!Opportunity.Id}&00N500000022TTd="Yes"

 

Woo Hoo!  Thank you so much!  I learned so much from you guys!!!