+ Start a Discussion
BaguiarBaguiar 

How to change a value on a selectList in a VF page through Apex

Hello!

 

I want to change a value on a SelectList item in a VF page I have named "Task_Type". The selectList is:

 

<apex:selectList id="rangedate" value="{!rangedate}" size="1" >
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
<apex:selectoption itemLabel="180" itemValue="180"></apex:selectoption>
</apex:selectList>

I want to pick another value of that list so that i can increase the coverage on my test Method. I can call the page through:

 

    PageReference pageRef = Page.Task_type;      


but I'm having a hard time with the syntax in how to set the value of "rangedate" to "30" for example. Thanks for the HELP!

Best Answer chosen by Admin (Salesforce Developers) 
BaguiarBaguiar

Found a solution on a diferent way. Instead of calling the VF page and chnage the selectlist value and run a test, I'm changing the string default value from the controller itself and then, run the test.

 

ControllerNEW CN= new ControllerNEW();

CN.rangedate='30';