+ Start a Discussion

Using URLFOR to link to Visualforce page

I'm tring to create a custom button and custom link to open a Visualforce page, and have tried both:





Once packaged and deployed, I'm getting errors about the page not being found.  I've read suggestions that using URLFOR() with $Page.pageName is the correct way to do this, but I can't find any examples of using URLFOR with $Page and querystring parameters.


Great timing, because I was about to post this. I really really need an answer to this, too.


I haven't even packaged it up yet and I'm getting errors that the page does not exist -- when I try to open the VF page from a custom object. It works fine for standard objects usiong the syntax /apex/pageName?id={!Account.Id}&type=Accounts but it doesn't work for custom objects at all. (I am aware of the namespace issue -- I'll deal with that when I package up.)


There should be a way to open a VF page from a URL on a custom object, right?


Theoretically, this might work: URLFOR($Page.pageName)?id={!Account.Id}&type=Accounts


But it returns an error that the URL does not exist.


According to Jill Wetzler (Salesforce) in this thread: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=6962


You should use a custom button that points to a VF page instead of a URL. That way we'll figure out the URL for you. and You can use an extension to bring in your custom functionality.


The clear implication is that SF does not want us to link to VF pages using a custom URL button. 


Here's the thing, though: I don't want to have to write a separate VF page for each object I want to put this custom button on. Potentially, my customers may put this button on every one of their standard AND custom objects. (Unlikely, but possible.) It is not feasible for me to write a separate VF page for each use case. It is very feasible, however, for me to write a single VF page and call it from a custom URL button with the appropriate parameters -- and right now I can't do that for custom objects.







Message Edited by XXX on 06-04-2009 02:17 PM

On further testing, I have found that /apex/pageName works for custom URL buttons popping up VF pages on both custom and standard objects.


The problem was caused by the second argument, for some reason I don't understand. This worked:




But this didn't work:




I can't explain why.