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
uxtx_timuxtx_tim 

pageReference with javascript

Trying to figure out how to set a string constructed in javascript to a pageReference partialURL object.

 

So Im generating a string in javascript that relates to a field in one of my objects.  If I could set that string to a pageReference('partialURL ')  in my controller, I could navigate to thepage for that specific object.  However, I can't figure out how to reference apex controller variables with javascript., specifically PageReference parameters.   Any suggestions or documentation you can point me to?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma

why don't you use redirection from the javascript itself like:

 

location.href = '/' + your Url string.

 

if it's a vf page then

 

location.href = '/apex/' + your Url string.

 

However if youy still want the redirection from the controller, you can create an action frunction on the page and can pass this string as a param . So from the action defined in the actionfucntion component you can get your redirection.

 

but still I would go javascript part as it is much simpler.

All Answers

Bhawani SharmaBhawani Sharma

why don't you use redirection from the javascript itself like:

 

location.href = '/' + your Url string.

 

if it's a vf page then

 

location.href = '/apex/' + your Url string.

 

However if youy still want the redirection from the controller, you can create an action frunction on the page and can pass this string as a param . So from the action defined in the actionfucntion component you can get your redirection.

 

but still I would go javascript part as it is much simpler.

This was selected as the best answer
uxtx_timuxtx_tim

Thanks for responding!  I can definitely do that in javascript and navigate away from the current page an open a new one.  It is a vf page btw.

 

What I'd like to do, and what I failed to make clear in my question, is use the partial page refresh so I'm not actually navigating away from the current page.

 

I'm going to look into the action function as I've never implemented it before - thanks again!

uxtx_timuxtx_tim

 


...you can create an action frunction on the page and can pass this string as a param . So from the action defined in the actionfucntion component you can get your redirection.

 

I have yet to understand the relationship between an <apex:param> and it's parent component.

 

The entry for the <apex:param component in the Visualforce Dev Guide is quite vague, as it gives no explaination for the example.

 

In that example

 

<apex:page standardController="Contact">

<apex:outputLink value="http://google.com/search">

Search Google

<apex:param name="q" value="{!contact.name}"/>

</apex:outputLink>

</apex:page>

     It looks like the resultant search will be for whatever name is associated with the current contact.

What is name="q"?  What would name="q" be used for?

Bhawani SharmaBhawani Sharma

Name is not for any use, it's just only an identification for tha param you created.