function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lapaullapaul 

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

Hi,

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

 

thanks

Paul

 

_Prasu__Prasu_

In Apex you can access the 

 

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

 

 

 



bob_buzzardbob_buzzard

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}"/>
</apex:commandButton>

 

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.

 

Pradeep_NavatarPradeep_Navatar

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')

{

          window.parent.location.replace('/{!$CurrentPage.parameters.id}');

}

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

gv007gv007

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