You need to sign in to do that
Don't have an account?
Shanmuga Prasath Pushpanathan
showing the custom object picklist value in a standard controller Visualforce page
I have implemented the below code which is working fine, but client want simpler code without cmplexity like using the inputfield tag
Controller :
public String selectedpicklistvalue{get; set;}
public List<selectOption> getpicklistvalue() {
List<SelectOption> picklistvalue= new List<SelectOption>();
Schema.DescribeFieldResult picklistvalueResult = customobject__c.picklist_field__c.getDescribe();
List<Schema.PicklistEntry> replace = picklistvalueResult .getPicklistValues();
picklistvalue.add(new SelectOption('',label.None_for_Picklist));
for( Schema.PicklistEntry r : replace) {
picklistvalue.add(new SelectOption(r.getLabel(), r.getValue()));
}
return picklistvalue;
}
VF page :
<apex:selectList id="selectedpicklistvalue" value="{!selectedpicklistvalue}" label="Picklist Value" size="1">
<apex:selectOptions value="{!picklistvalue}">
</apex:selectOptions>
</apex:selectList>
Controller :
public String selectedpicklistvalue{get; set;}
public List<selectOption> getpicklistvalue() {
List<SelectOption> picklistvalue= new List<SelectOption>();
Schema.DescribeFieldResult picklistvalueResult = customobject__c.picklist_field__c.getDescribe();
List<Schema.PicklistEntry> replace = picklistvalueResult .getPicklistValues();
picklistvalue.add(new SelectOption('',label.None_for_Picklist));
for( Schema.PicklistEntry r : replace) {
picklistvalue.add(new SelectOption(r.getLabel(), r.getValue()));
}
return picklistvalue;
}
VF page :
<apex:selectList id="selectedpicklistvalue" value="{!selectedpicklistvalue}" label="Picklist Value" size="1">
<apex:selectOptions value="{!picklistvalue}">
</apex:selectOptions>
</apex:selectList>
Greetings to you!
The easiest way to display an SObject field that is of type picklist is:
The framework will recognize that it is a picklist field and render a select list and the options defined for the field automatically without you having to do any more work. It is only necessary to use apex:selectOptions or apex:selectOption if you want to build the options list yourself.
Reference: https://salesforce.stackexchange.com/questions/51492/using-apexselectlist-with-standard-controller
Please refer to the below links which might help you further.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputField.htm
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thanks for the quick response
Yes, You are right for the scenerio which I have mentioned above, but the thing is I have to get the selected picklist value in the controller and map it to other object.
Note : As this is a Standard controller for case object, I'm not sure how to get the selected custom object's picklist value to the controller.
Regards,
Shanmuga Prasath