+ Start a Discussion

How to add query string parameters to a command button and how to retrieve them


How do you add query string parameters to a command button and how do you retrieve them in Apex code? Please advice.






In Apex you can access the 


String strQueryString = ApexPages.CurrentPage().getParameters().get('QueryString name');





You use the apex:param component nested within the command button.  E.g.



<apex:commandButton action="{!getContact}" value="GetContact">
   <apex:param name="cont" value="{!contact.id}" assignTo="{!idForCont}"/>


The assignTo attribute defines the controller property to store the parameter in.  Thus when your getContact() action method is invoked, idForCont will contain the chosen id.



Try a different logic : Call action attribute in a command button, create a pagerefrence method in controller and create a url with some parameters. You can check the parameter in the page as given below :


if('{!$CurrentPage.parameters.rf}' == 'No')




where rf is parameter which is assigned in URL in controller.


The above soloution is only way other wise


<apex:CommandButton value ='{!URLFOR( parameters)}/>

pass the parameter using URLFOR and get values using   system.currentpage.methods