Newer Version Available

This content describes an older version of this product. View Latest

Getting and Setting Query String Parameters on a Single Page

Having seen examples of both getting and setting query string parameters, this example shows how the two actions can be combined on a single page to produce a more interesting result. Based on the example from Getting Query String Parameters, the following page makes the name of each contact in the list a hyperlink that controls the context of the detail component below it.

This is possible by:
  • Wrapping the data table in an <apex:form> tag
  • Turning each contact name into an <apex:commandLink> that sets the cid parameter appropriately with an <apex:param> tag

When used with a standard controller, command links always entirely refresh the current page with the new information added to the page—in this case, an updated cid that updates the contact detail component.

After saving this markup, refresh your browser with the id query string parameter but without the cid parameter in the URL For example,
Initially the contact detail page is not rendered, but when you click a contact name the page renders the appropriate detail view.

If you use the id parameter in a URL, it must refer to the same entity referred to in the standard controller.

Note