How to Render Lookup field as Picklist while Querying an Object

The issue that I ran in today was discussed at bunch of fourms and I am writing a code snippet to help resolving this problem How would I di...

The issue that I ran in today was discussed at bunch of fourms and I am writing a code snippet to help resolving this problem

How would I display or populate picklist by querying an object ? How would I render a lookup-field as Picklist in Salesforce (visual force) ?

Whenever a user goes populate lookup field,  the Salesforce open new window every time to search the record, which is very common behavior seen for lookup field. I want to limit the record and want to render the lookup browser window to picklist wihout converting 'fieldtype' from 'lookup to picklist'.

How can I do this, also if I want to limit the options of picklist by querying an object what could be done to meet this requirement. The code below explains the simple steps to achieve this

Instructor__c : Lookup field to user, which will be rendered as picklist instead

VisualForce Page code 



In controller below, I am querying User object matching profiles and used List<selectOptions> which accept value and id as custom parameters
SelectOption option = new SelectOption(value, label);

Read more about SelectOption class here

Whatever I chose in picklist, the id of chosen value will be assigned to lookup field (instructor__c)  which will UserId.

Note - The method getProfilesOptions() will populate the picklist and here how how you  can invoke it
<apex:selectOptions value="{!ProfilesOptions}"> </apex:selectOptions>

What Others Are Reading