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
Ramesh y 10Ramesh y 10 

How to get the pick list values in apex controller.

Hi All,

I need help to get the picklist values and using these values in visualforce page to hide/show the pageblock.

My requirement.
I have a object called Book in may app . Book have one field called sample1(picklist) and  it has two values..(Yes, No).

Then , I have to show entire panel based of these values( yes, or no) . Below is my code.

Apex class :
public class bookcontrol
{
public list<Book__c> allbooks {get; set;}

public list<Book__c> getBooks()
{
allbooks= [select sample1__c from Book__c where sample2 = :object2.field2 limit 1 ];
return allbooks;
}
}
(there is some logic behind the above SOQL query, it is checking another condition)


Here my question is above returened " allbooks" have my field picklist values are not?

can i use above variable in visualforce page.

My visualforce page is :
.........
......
<apex:panelGroup rendered = "{! IF(allbooks.sample1__c == 'Yes' , true, false)">
........
.......
</apex:panelGroup>

Will that above code wii work?

How to get those picklist values to my visualforce page to compare the logic. I need to show that entire panel if my field value is Yes.

Appreciate your help. 

Thanks
R
James LoghryJames Loghry

Depending on the rest of your visualforce and apex, it looks like it should work.

If you want to display the picklist values as well, you could do something like:

<apex:inputField value="{!book.Sample1__c}" />  Where book is an individual instance of your Books list.  For example, when you iterate through the books list in a repeat.

Grazitti TeamGrazitti Team
Hi Ramesh,

You have to do some change in the Vf page.

Please see the code below:

VF Page:
<apex:panelGroup rendered = "{! IF(allbooks[0].sample1__c == 'Yes' , true, false)">
........
.......
</apex:panelGroup>

Please mark as best answer if it solves your problem.

Regards,
Grazitti Team,
www.grazitti.com