[SalesForce] Setting Visualforce Page url parameters within standard page layouts

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?

ApexPages.currentPage.getParameters().put('Id',myId) 

Best Answer

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.

Related Topic