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
sanjeev342sanjeev342 

How do I reference picklist values in a controller?

I'm trying to create a rule.

 

IF(value X is selected in picklist)   ------->  THEN( make sure List Y has at least one value)

 

 

How do you find the value of a picklist in a Controller Class?

 

 

Thanks,

Sanjeev

kcpluspluskcplusplus

Are you trying to find all of the picklist values of a field? 

 

You can do a Schema field describe

List<Schema.PicklistEntry> picklist_describe = Opportunity.StageName.getDescribe().getpicklistvalues(); 
Set<String> values = new Set<String>(); 
for(Schema.PicklistEntry pe : picklist_describe){
     values.add(String.valueOf(pe.getValue())); 
}
system.debug(values);

 That will give you all of the values of a given picklist field. Try it in execute anonymous to see what it gives and reference this doc http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm

 

--KC

sanjeev342sanjeev342

KC,

 

    Thanks for the reply, what I'm trying to do is find out what value was selected so that I can run different code based on that value.

 

How do I go about doing this?

 

Thanks,

Sanjeev

Yoganand GadekarYoganand Gadekar

You will need to bind the picklist field to a variable in the controller class using {gte;set;}.

This will make sure that the selected value for the picklist is available in the controller. Then depending on this value u can run the required peice of code.