You need to sign in to do that
Don't have an account?
bozotheclown
Can VF Allow Me to Swap a Lookup with a Picklist?
Hello. Does anyone know if it is possible via Visualforce code to substitute a lookup with a picklist?
We all know that, by default, salesforce.com creates a lookup situation when associating the master record values on a child record.
Well, I am trying to figure out if Visualforce code will allow me to present things a little differently for my users.
Is this possible? Does anyone have any suggestions?
Thanks in advance.
How big do you want your picklist to be?
The way I accomplished this is that I made a custom object and put all the possible Lookup Values as part of this Custom Object. Then I build a selectoption list in Visualforce and Apex itself. It may not be exactly what you're looking for but it might point you in the right direction.
VF:
Now in the Controller I'm using getItems, which is what's referenced from SelectOptions
Edit: Forgot an important step. The getters and setters for the custom object in question have to be written in the Apex code. In this example the selectlist value = countries, so in my Apex Code we instantiate the following:
Apex:
And to sort the List, we have a SortOptionList. Since the Records in the custom field are pulled from the Database, they won't necessarily be in the same order as you put them in. So if you're looking for alphabetical order, use the following simple sort:
Like I said it might not be EXACTLY what you're looking for, but this will build a picklist from the Lookup Relationship. There are size requirements to a picklist that I don't know off the top of my head, but if you try and have a very large picklist you might run into that limit.
Hope this helps.
Also, note that there have been small changes to the code, so this won't copy-and-compile. Just an FYI.