+ Start a Discussion

Simple Custom Button Code in Visualforce

Hi Everyone, 


I have almost completed a large project I am working on and, of course, I am hung up on my last small task. I need to create a custom button on my visualforce page that clones the current opportunity and automatically sets some field values. I would like to do this as simply as possibly. 


I can do it very easily with an outputlink:



value="/{!Opportunity.Id}/e?clone=1&retURL=%2f{!Opportunity.Id}&00Nc0000000QhbH=1&00NC00000050hhz={!Opportunity.Id}"> New Child Opportunity



Can someone explain how to do this simple link using a PageBlockButton or CommandButton? Thank you!



you can simply write this


<apex:commandButton value="Clone" action="{!URLFOR($Action.ObjectName.Clone,<ObectName>.id)}"/>


The only problem with this is that it will not help me set the special field values. For example,in my URL, i set the field (00Nc0000000QhbH) to 1


My button code does not do an exact clone, it clones but also sets a few values manually.