1

I have a very simple requirement which is to create a page in Visualforce. Take a value input by user & then pass the value to be used as a filtering criteria in a report in an outputlink.

There is no need to use any controller to link to any objects.

The outputlink will work if only I hard code the value instead of taking a entered value.

Would appreciate any help on this as I am totally new to Salesforce & Visualforce.

Thank you.

Here is my code:

<apex:page>
<apex:form>
<apex:inputText id="theTextInput"/>
<apex:outputLink Value="https://xx.salesforce.com/1111111111ABCDE?pv0=&{!$Component.theTextInput}&pv1=01/01/2018">click me</apex:outputLink>
</apex:form>
</apex:page>
0

You can simply use anchor tag instead of <apex:outputlink/> with use of javascript function from href attribute as follows:

    <a href="javascript:window.open('https://cs21.salesforce.com/00Oq0000000YUvUEAW?pv0=' 
    + document.getElementById('{!$Component.theTextInput}').value 
    + '&pv1=2018-01-01');">
    click me
    </a>
1
  • pls close this question, so other members can find this useful Jan 12 '17 at 5:19
0

I suggest using an apex controller where you can control certain attributes the url string that you are attempting to link to...like the salesforce instance, record id, and filter values.

It will be much easier to maintain across multiple environments, etc.

1
  • 1
    Thank you for the answer and welcome to SFSE. It would be great if you could post some example code for better illustration.
    – Ashwani
    Jan 12 '17 at 3:26
0

First ,how you plan to get the value without controller.I would say it should be in javascript or it passed in URL.My opinion is to use controller, it will make the code cleaner

Second {!$Component.theTextInput} won't help you to get a value of inputText.It will help you to get the ID.It will return you something like this . j_id0:j_id1:theTextInput

In order to get the value in javascript, you need to do something like this

<apex:inputText id="theTextInput" onchange="getParam()"></apex:inputText>
 <script> 
function getParam(){
var a =document.getElementById("{!$Component.theTextInput}").value;
alert(a);
}
</script>

Third I notice that '&' next to '=' , should it be something like this:

pv0={!whatevervalue}&pv1=01/01/2018
5
  • ? isn't pv1=2018-01-01
    – cropredy
    Jan 12 '17 at 3:18
  • I m not sure &pv1=01/01/2018 but it correctly call .but if it use for apex date then it maybe need to change. I am referring to pv0=&{!$Component.theTextInput} , '=' should be followed by parameter , in this it use '&' which append to next new param.the output should pv0=value1&pv1=value2 ...
    – unidha
    Jan 12 '17 at 3:33
  • Thank you ! i have added the function & remove the '&' but i am still getting the same result. Am i missing something ?
    – Ben
    Jan 12 '17 at 4:48
  • Check the Second opinion -- $Component wont return you value, it's only return you Id. you can get value from javascript or simply using controller.
    – unidha
    Jan 12 '17 at 5:01
  • oic.... i get what you mean now. thank you for the explaination. :)
    – Ben
    Jan 12 '17 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.