You need to sign in to do that
Don't have an account?
Matt Folger
How to have a picklist inputted into a user-driven SOQL query?
Hi, I'm building this user-driven input SOQL query (my life's work) and I'm trying to see if it is possible for a picklist to be one of the fields that can be pulled for an input query? I'm not seeing the apex:inputXXXX command that would do this, but I'm hoping it can be done through some other method.
I have a Inquiry_Status__c field that is a picklist and can only have: "Original", "Inquired" or "Responded" field information, so having the user have to manually type that in the input field is kinda nutty and prone to problems, mistypes, forgetting what the field values CAN be, etc. Is there a way to do this?
(I presently have the SOQL query working via a <apex:inputText ......> command, but a picklist would be awesome)
I have a Inquiry_Status__c field that is a picklist and can only have: "Original", "Inquired" or "Responded" field information, so having the user have to manually type that in the input field is kinda nutty and prone to problems, mistypes, forgetting what the field values CAN be, etc. Is there a way to do this?
(I presently have the SOQL query working via a <apex:inputText ......> command, but a picklist would be awesome)
Please insert this code in your controller.
public List<SelectOption> getInquiryStatus(){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('-- Select Inquiry Status --', ''));
options.add(new SelectOption('Original', 'Original'));
options.add(new SelectOption('Inquired', 'Inquired'));
options.add(new SelectOption('Responded', 'Responded'));
return options;
}
Step 2:
Please replace the line "<apex:inputText value="{!Ven_Inquiry_Stat}" label="Inquiry Status"/>"
with the following code:
<apex:selectList id="inqStatInp" value="{!Ven_Inquiry_Stat}" size="1" label="Inquiry Status">
<apex:selectOptions value="{!InquiryStatus}"/>
</apex:selectList>
This will give you a drop down list on the page. The value that user selects will be present in the variable "Ven_Inquiry_Stat". You can use that value to form the query.
Let me know if this solves your issue or you still have some problems.
Thanks,
Kaustav
All Answers
<apex:inputField value="{!inqInst.Inquiry_Status__c}" id="inqStatInput" />
This will render the field as a picklist in your VF page.
Thanks,
Kaustav
Here's the code line I inputed.
But I get these errors: If I changed the line of code in question to this, (which is how the variable is defined in the controller): Then I get this:
Hmm, so I'm not seeing how to do that? Remember, it's not a direct record that we are referencing with these pull downs, they are placeholders (if that's the right term) for a controller to search based on these criteria.
Controller:
Please insert this code in your controller.
public List<SelectOption> getInquiryStatus(){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('-- Select Inquiry Status --', ''));
options.add(new SelectOption('Original', 'Original'));
options.add(new SelectOption('Inquired', 'Inquired'));
options.add(new SelectOption('Responded', 'Responded'));
return options;
}
Step 2:
Please replace the line "<apex:inputText value="{!Ven_Inquiry_Stat}" label="Inquiry Status"/>"
with the following code:
<apex:selectList id="inqStatInp" value="{!Ven_Inquiry_Stat}" size="1" label="Inquiry Status">
<apex:selectOptions value="{!InquiryStatus}"/>
</apex:selectList>
This will give you a drop down list on the page. The value that user selects will be present in the variable "Ven_Inquiry_Stat". You can use that value to form the query.
Let me know if this solves your issue or you still have some problems.
Thanks,
Kaustav
You shoould use <apex:actionSupport> with <apex:param>,something like below :-
Probably you can try to user your object instance instead of String. Lets say the picklist field is on "Vencorr__c"
in controller
in page you can do
Now replace Ven_Inquiry_Stat with ven.Inquiry_Status__c
I went with kaustav goswami's and it worked without incident, so I'll leave well enough alone.
Thanks everyone.
=)