title: Custom Button or Link to a Visualforce page with a custom controller
body: <p>I have a Visualforce page using a custom controller that is used to edit multiple records under an opportunity.</p>
  
  <p>I'd like to create a custom button or link from Opportunities to this Visualforce page.</p>
  
  <p>Currently the link looks like:</p>
  
  <pre><code>/apex/ExamplePage?oppId={!Opportunity.Id}
  </code></pre>
  
  <p>This works fine in the development sandbox, but when it is deployed as part of a managed package the link breaks as the page reference doesn't have the namespace prefix.</p>
  
  <p>I found the post <a href="http://boards.developerforce.com/t5/Visualforce-Development/Managed-Package-Redirecting-Problem/m-p/114341">Managed Package Redirecting Problem</a> on the Force.com Discussion Boards which implied it should be possible to use $Page to reference the Visualforce page in the URL. E.g. </p>
  
  <pre><code>{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}
  </code></pre>
  
  <p>But doing so only gives me the syntax error:</p>
  
  <blockquote>
    <p>Error: Field $Page.MyExamplePage does not exist. Check spelling.</p>
  </blockquote>
  
  <p>There is another part to the post that suggests using an Apex class and Execute Javascript to work around it. But it appears to me that this has just moved the namespace issue into the Javascript.</p>
  
  <p>How can I safely reference the Visualforce page to work both inside and outside a managed package?</p>