You need to sign in to do that
Don't have an account?

Invoking a Visualforce page in a managed package
Hello,
This might be not pure VF development question, but still...
I have a Visualforce page that uses custom controller
Visualforce page name: myVFpage
Opportunity Page layout has a button with the following URL:
/apex/myVFPage?id={!Opportunity.Id}
That is calling the VF page and passing Opportunity Id as a parameter.
Everything works fine in my developer org.
-------------------------------------------------------------------------------------------------------------------------------------------------
Now, the problem comes when I create a managed package (managed-beta) and install it in a destination org.
When I press the button I get an error message:
'Page myvfpage does not exist'.
However, if I enter the following URL directly into a browser, the page shows up:
https://my_namespace_prefix.na6.visual.force.com/apex/myVFPage?id=0068000000MLQE6
What am I doing wrong?
I guess this is somehow related to a namespace prefix.
This might be not pure VF development question, but still...
I have a Visualforce page that uses custom controller
Visualforce page name: myVFpage
Opportunity Page layout has a button with the following URL:
/apex/myVFPage?id={!Opportunity.Id}
That is calling the VF page and passing Opportunity Id as a parameter.
Everything works fine in my developer org.
-------------------------------------------------------------------------------------------------------------------------------------------------
Now, the problem comes when I create a managed package (managed-beta) and install it in a destination org.
When I press the button I get an error message:
'Page myvfpage does not exist'.
However, if I enter the following URL directly into a browser, the page shows up:
https://my_namespace_prefix.na6.visual.force.com/apex/myVFPage?id=0068000000MLQE6
What am I doing wrong?
I guess this is somehow related to a namespace prefix.
This had me stuck as well until it was pointed out that I should be using the namespace for the package when referencing the page. example:
Package name = myPackage
so /apex/myVFPage?id={!Opportunity.Id} becomes /apex/myPackage__myVFPage?id={!Opportunity.Id}
This will direct you correctly to your page. Remember that you need 2 _s between packagename and pagename.
Hope this helps.
All Answers
Thanks for your resposnse.
I tried that too.
But from what I understood from your previous post:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=6856
it is only possible to point a custom button directly to a VF page if the latter has a standard controller.
In my case the page has a custom controller, so this approach seems to be non-doable.
Thanks,
Shamil
If this is the only option, I will transfer my custom controller into an extension.
Thanks, this is a good suggestion.
...but still let me ask you a stupid question: Can you please confirm that my approach with URL is not doable?
Thanks.
I use
$Page.myVFPage
in VF pages and
Page.myVFPage.getURL()
in Apex code. I hope that it will still work when I upload my managed package.
Have you tried this already ?
You are right this works in VF pages in and Apex, but in my case I need to invoke a page from a custom button on Opportunity.
The $Page global variable is only available for Visualforce pages, so this will not work for me.
Let’s sum up…
What I had before:
1. Visualforce page: myVFPage
2. Custom controller: customVFCon
3. Tester Class: customVFConTester
4. Custom button of type URL on Opportunity that is invoking the page and passes Opportunity Id as a parameter:
/apex/myVFPage?id={!Opportunity.Id}
Problem:
In a managed package the custom button doesn’t invoke myVFPage with an error message:
'Page myvfpage does not exist'.
Cause: namespace prefix is not automatically handled for the URL specified in the custom button.
Solution:
Here is what I did to solve the problem (based on Jill Wetzler’s suggestion http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=6965
1. Modified myVFPage and linked it to a standard Opportunity controller with an extension:
2. Created a controller extension and moved the logic from my custom controller customVFCon into it.
3. Modified tester class: customVFConTester. I had to do this because controller extensions are instantiated a bit differently (first you have to create a standard controller, then create extension instance, pass standard controller object to it). Here is a useful thread on this: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=692#M692
4. Modified custom button on Opportunity: set the ‘Content Source’ to ‘Visualforce Page’ and selected myVFPage from the ‘Content’ drop-down.
For a custom button that is directly linked to a VF page, the id parameter is automatically passed behind the scene.
However, to my mind, the approach is not general enough to solve all similar issues.
Because in my case the only parameter that was passed to my custom controller through URL was Opportunity id, so when I moved everything into an extension I didn’t have to worry about this much.
Now, what if there were several parameters? How this can be accomplished without specifying the URL?
Shamil - Thank you for your thorough exploration of the issue & summary of your workaround. I can only guess how many hours it saved me.
I think it would be interesting and helpful to know whether this is something that is going to be addressed, or whether we should adopt this workaround as a standard best practice for pages that might ever be called via a button. For safety this might mean never using a custom controller at all (use an extension instead), because you never know when you might want to call a page from a button at some later point.
I also wonder about what the downside to this workaround might be, either in terms of resource usage or performance, since we're instantiating a large controller much of which we may not need. Or are there other downsides we haven't considered. For one, it looks a little convoluted when the straightforward approach would be to just use a custom controller.
Thanks.
This had me stuck as well until it was pointed out that I should be using the namespace for the package when referencing the page. example:
Package name = myPackage
so /apex/myVFPage?id={!Opportunity.Id} becomes /apex/myPackage__myVFPage?id={!Opportunity.Id}
This will direct you correctly to your page. Remember that you need 2 _s between packagename and pagename.
Hope this helps.
Richie,
thanks for posting, I had exact same issue, but are you sure it worked with package name?
I did some r&d on how it was populating the VF url on my test org, for me I had to enter the namespace.
Just replacing package_name in the url you have with namespace works like a charm ..
regards
SF Partner