[SalesForce] Open a visualforce page from a managed package page: URL No Longer Exists

I am trying to open a normal visualforce page (that is NOT a part of the managed package) from a visualforce page that is IN managed package.

This button I have on the visualforce page in manage package:

<apex:commandButton value="Open" onclick="window.open('apex/MyPage'); return false;" />

The MyPage is NOT in the managed package.

By clicking on the button a new popup window appears, so javascript works well.
But the problem is that I am getting the following error message and no content of the MyPage:

URL No Longer Exists
You have attempted to reach a URL that no longer
exists on salesforce.com.

After some research I've found a difference between URL of the both pages.

Managed package visualforce page with that command button:

https://customDomainName--PREFIX.csXX.visual.force.com/apex/PageInManagedPackage

Another page that should be opened (MyPage, not in managed package) is opened with the same prefix in URL. But if I replace the PREFIX with a c then the page will load without problems:

https://customDomainName--c.csXX.visual.force.com/apex/MyPage          <- this works
https://customDomainName--PREFIX.csXX.visual.force.com/apex/MyPage     <- this not

How you can see the only difference is that external page opened with a prefix in URL could not be shown 🙁

My question is, what is wrong with my button? Why an "external" page opens with a wrong URL? Is it a managed package "feature"? How can I avoid this?

Best Answer

Issues:

  1. URL No Longer Exists
    • Error is happening because your path to the page is incorrect and is missing the leading / which creates a URL which is relative to the current page rather than relative to the host.
  2. Path to the page outside of the managed package namespace
    • The default VF namespace is c__ and you can specify this in your page path. This allows you to avoid hardcoding a fully qualified URI.

<apex:commandButton value="Open" onclick="window.open('/apex/c__MyPage'); return false;" />

Related: How to redirect to default namespace vf page from managed package vf page?

Related Topic