What is the best (or preferred method) of setting a url parameter on a visualforce page embedded on a standard layout page?

This is easy to do when creating a custom link or a button, but I don't get how to do this on page load via the Apex Controller for the page.

When using a custom button you can do something like /apex/MyPageName?parameter=value

Can I use something like this?


When your Visualforce page is rendered inside the standard record view, it will be passed the id of the current record as a URL parameter and that is all - you cannot add further parameters. Any additional parameters that you add in a controller will not have any effect as the controller chain (standard plus any extensions) is already have been constructed and the standard controller has retrieved the record it is managing, populating fields based on those you have used in your page.

If you are using information that is known to your controller, is there any need to add this to the parameters? If you already have it you can carry out any server side processing that you need to, and if it will be used client side you can expose this as a controller property - you could also check the parameters first and then fall back on a controller property if you need to.

If you want to change the underlying id of the page, so pull back a different record to the one that the standard view is displaying, you'd need to create a new pagereference, set the id and then carry out a redirect to that page. If you can do this server side (through the page 'action' attribute) that is a much better experience for the user than waiting for the Visualforce page to load, followed by a redirect to another page.

  • Thanks for that info Bob. Especially about the record ID being automatically available to the VF class. The only thing I needed was the record ID, by doing a query for that I can get the rest of the data my class logic works with. – akarnid Apr 2 '14 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.