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
Vinnie BVinnie B 

How to create a simple VF page that redirects immediately to a new URL

I know this has got to be simple but I just can't figure it out after hacking away for an hour.  I am not experienced at this.

I'm simply trying to override the New button on a custom object to a URL which pre-populates the Name field.  The URL was easy to develop (below).  It works just like the standard New button but one field is populated with some text.  (We use a workflow rule to set the Name field so there's no need for the user to enter anything.)

  https://na18.salesforce.com/a0o/e?Name=[Set%20by%20Workflow%20Rule]&retURL=%2Fa0o%2Fo

When I want to change the default button it asks me for a VF page.  I have tried creating a simple VF page that just redirects to the URL above.  I'm a pretty novice VF developer and this simple task has got me struggling.

Thanks!!
SlashApex (Luis Luciani)SlashApex (Luis Luciani)
Hi Vinnie,

You should not need to create a VF page in order to achieve this.

Follow this steps:
  1. Go to the Setup page
  2. Go to Build > Create > Objects > Click on the label of your custom object
  3. Scroll down and click the button that says "New Button or Link"
  4. Enter a label for your new button. I would recommend something like "New <object Name here>"
  5. Select the display type of the button. This determines where you can put it.
  6. Pick a behavior. This is up to you
  7. Select URL as the content source
  8. Finally, on the big text area, just enter: /a0o/e?Name=Set%20by%20Workflow%20Rule&retURL=%2Fa0o%2Fo
After saving your new button, you will have to add it to the page layout or wherever you want to configure it to show.

Good luck!
Vinnie BVinnie B
Thanks!  I've figured out how to add this button to any page or related list where the New button for that object might be found.  However, I want to change the generic New button that one sees for that object.  For example, when you just view a list of Contacts, there's a New button there.  There's no page layout associated with the default list of Contacts that one sees by clicking on Contacts. 

Also, it seems much cleaner to just change the default New button for an object so that wherever one tries to create a new object of this type they will get this button as the default behavior.

It looks like I just need a VF page that will automatically redirect to a URL that I will provide.
SlashApex (Luis Luciani)SlashApex (Luis Luciani)
I see, it seems like you have done your homework!

Here is how to accomplish this with a VF page. You can leverage the Page action which is the first thing that loads when a page is called. The only disadvantage here is that it will be a bit slower for users, and they will most likely notice that they are being redirected.
 
<apex:page standardController="OBJECT API NAME HERE" action="/a0o/e?Name=Set%20by%20Workflow%20Rule&retURL=%2Fa0o%2Fo">

</apex:page>