+ Start a Discussion
zen_njzen_nj 

trying to create button to invoke VF page, Content field empty even though I have 3 VF pages

I have set up a visualforce page (using a custom controller) on a custom object (call it FSL) and that works ok if I was evoking it by doing something  like:

.../apex/VisualPageName/?id=a140000R000dx1df  (whatever object id for an FSL entry that I want to run it against)

But now I want to create a custom button for FSL and associate it with the visualforce page so that when the user is a a particular FSL entry, they can click on this button and it will invoke the visualforce page (and it's workflow).

I thought I had done it before and when I did it in the past, I would click on the Create new custom button and select Detailed Page Buttno and then in the Content Source, select "Visualforce Page". And when I do that, I should be able to see in the Content pull-down menu a list of all the available VisualForce Pages.

But when I do this, the Content pull-down menu is empty, even though I have 3 visualforce pages set up.

Am I forgetting to do some additional configuration/setup to "publish" the visualforce page? 
It's strange but I can see that I do have an older set up where I created a Case custom button that is invoking a Case visualforce page. But if I try to create a new button and use the exact same set up in the custom button, I would still see blank selection in the Content field.

Can someone please shed some light on this?
thx

Zen


Sam.arjSam.arj
Check this post out:

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=8508
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=8508


jwetzlerjwetzler
Your page must use the standardController for the object you wish to override if you're going to override the New, Edit, View, etc. actions for an object.  Any custom logic you need should go into an Apex extension.

By the way, I have logged a bug for our documentation writer to make this explicit in the docs.  I'm not sure why it's not in there.


Message Edited by jwetzler on 01-08-2009 12:50 PM
zen_njzen_nj
Thx for the replies. Now I remember how I did it last time.

You guys are correct and that only visualpage using standard controllers will be available/visible when trying to choose from the Content in creating  custom button.

And what I did last time was to trick salesforce so that I can actually create custom button that will invoke visual page that is using a custom controller. So now that I remember that this was the problem, I was able to do it again. Essentially what I did was:

1. create a dummy visualforce page (essentially a holder) called VF_FSL and in that visualforce page, just declare it to be use
   standard controller.  So in my case I would just create a dummy visualforce page that really only have 3 lines:
   <apex:page standardController="FSL">
    Hello World
    </apex:page>

2. I then went ahead and create a custom button for my custom object FSL and this time, when I indicate that my Content
    Source  is VisualForce page, now the Content pulldown will show VF_FSL as an available option and so I can select this.
    I then add this custom button to my page layout accordingly and so now I have linked the visualforce page to my normal
    page layout via this custom button.

3. Now I just need to edit my dummy visualforce page and change it so that it's no longer using standardcontroller but a
    custom  controller, and create the appropriate Class for that. And once that's done, I can still use the custom button to
    invoke this modified visualforce page which now is using custom controller for enhanced functions.

jwetzlerjwetzler
Why are you doing so much work to "trick" it into doing something that is already supported?  This is not something that I would recommend, nor is it something that I can promise won't break in the future (what if we make it impossible for you to change the controller type of a page that's already bound as an override, which I believe is something we already have a bug for)?

The page you have will work fine as long as you give it a standardController, and use the current controller you have as an extension.  Then you get all of the functionality of the standardcontroller, including even easier access to the id than having to ask for the current page parameters.  If you're not familiar with extensions you should review the documentation for them.  They are just as easy as writing a controller, and you get extra functionality.

Your "workaround" is not something that should be suggested as a solution.  There is already support built into Visualforce for your needs, and I'd suggest that you go that route rather than hacking something in that may not work in the future.
zen_njzen_nj
Yeah I am a newbie to VF, so didn't know that I can use the standard controller extension to enhance it. Will take a look at how that's done then. thx.
TehNrdTehNrd
If this is a custom button why not just make the content source of the button a URL and then enter:

/apex/pageName?id={!FSL.Id}

You'd also want the behavior to display in existing window without sidebar or header


Message Edited by TehNrd on 01-09-2009 09:22 AM
zen_njzen_nj
I did start this out using url for custom button. I switched to visualforce page because I needed to have logical/decision capabilities.
That is, depending on what values are in the FSL fields, I want to have certain things populated. Didn't know how (or if there is a way) to have url code perform logical checks and then assign specific values depending on the outcome of the logical check (i.e. if field1 = 'abc', then assign xxxx to yyy, else assign zzzz to yyy)
TehNrdTehNrd
In your controller constructor query the FSL object and perform any logic/defaulting values there.


Message Edited by TehNrd on 01-13-2009 11:43 AM
zen_njzen_nj
You lost me.  Not sure what you are referring to.
I have corrected this per jwetzler recommendation so that I am now using a controller extension and this way I can use the logic/defaults which I don't think you can do using url (for custom button).

TehNrdTehNrd
If you've got it working with Jill's recommendation stick with that.