Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I have a Visualforce page using a custom controller that is used to edit multiple records under an opportunity.

I'd like to create a custom button or link from Opportunities to this Visualforce page.

Currently, the link looks like:

/apex/ExamplePage?oppId={!Opportunity.Id}

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.

I found the post Managed Package Redirecting Problem 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.

{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}

But doing so only gives me the syntax error:

Error: Field $Page.MyExamplePage does not exist. Check spelling.

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.

How can I safely reference the Visualforce page to work both inside and outside a managed package?

1 Answer

0 votes
by (32.1k points)

Best way to do this is from an Apex PageReference return value. 

Something like this will work:

public PageReference returnPage()

{

   return Page.MyExamplePage;

}

Then you can call this from Visualforce:

<apex:commandButton value="Go To New Page" action="{!returnPage}"/>

The transaction will be handled by the Apex page call.

Browse Categories

...