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
sid_devsid_dev 

How to access parameters from URl in Visual Force page

Hi,

 

I have a custom button which is passing some parametes in the URL. I want to access the querystring paramters in the VF page and assign the value to the inputField

 

I have tried the following:

 

Email: <apex:inputField value="{!$CurrentPage.parameters.email}"/><br/>

 

But I get the error message that 'paramter' does not exist. Can anyone point me to a solution or to a post where the solution is already provided.

 

Thanks

Rajesh ShahRajesh Shah

Saw this example from the developers guide

 

<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>

 

 What you are doing seems correct. Are you sure the email parameter is present in the url?

 

sid_devsid_dev

But how will I get that value in the inputField. I need to show the email value in a text box.

Yes I am getting the email in the URL

sid_devsid_dev

I solved the problem by using javascript instead.

Need to look for the id by doing view source and then assign the parameter.  Since contact object doesn't have any value and it is being passed in the URL through a custoe button I used JS to find the id and assign the value.

 

<apex:inputField value="{!contact.Email}" id="Email"/>

 

document.getElementById("j_id0:j_id2:j_id3:j_id4:Email").value = "{!$CurrentPage.parameters.email}";

Rajesh ShahRajesh Shah
It would be better if you access the element in the JavaScript using proper heirarchy and component ids. Using j_id1:j_id2 .... can cause a problem as it might change in another org or when new components are added.
sid_devsid_dev

Hi Rajesh,

 

Can you please elaborate a little more. I am new to this so I am not sure abt the methodology you are talking abt.

 

Thanks,
Sid

Rajesh ShahRajesh Shah

See the following code

 

<apex:page id="ApproveTicket" > <script> // Javascript Code function closeWindow() { var errorMessage = document.getElementById("ApproveTicket:ApprovalForm:ErrorHidden").value; } </script> <apex:form id="ApprovalForm" > <apex:inputHidden value="{!errorMessage}" id="ErrorHidden" /> </apex:form></apex:page>

 

 Its better to access the elements using the heirarchy and the id instead of using ids from Source. This way you are sure that it will work on all the browsers and environment.