You need to sign in to do that
Don't have an account?

How to display lookup field on a visual force page
I have a lookup field to Account object on "Application" object with some filter criteria. The fieldname is Congressional_District__c on Application object.
Here is my visualforce code:
<apex:inputField required="true" id="CongressionalRepresentative" value="{!CongressionalDistrict.Congressional_District__c}" />
where CongressionalDistrict is the method name in the apex class.
Here is the method in my apex class:
public Application__c getCongressionalDistrict()
{
return [select Congressional_District__c from Application__c limit 1];
}
This returns me a text field(instead of a lookup) which constantly displays the first value in the lookup field(instead of multiple values in lookup so that user can select a value). Attached is the screenshot:

Also if I remove limit 1 at the end and do
return [select Congressional_District__c from Application__c];
it gives me error.
Any help would be appreciated.
Here is my visualforce code:
<apex:inputField required="true" id="CongressionalRepresentative" value="{!CongressionalDistrict.Congressional_District__c}" />
where CongressionalDistrict is the method name in the apex class.
Here is the method in my apex class:
public Application__c getCongressionalDistrict()
{
return [select Congressional_District__c from Application__c limit 1];
}
This returns me a text field(instead of a lookup) which constantly displays the first value in the lookup field(instead of multiple values in lookup so that user can select a value). Attached is the screenshot:
Also if I remove limit 1 at the end and do
return [select Congressional_District__c from Application__c];
it gives me error.
Any help would be appreciated.
If my understanding is correctly, you try to display the field (Congressional_District__c) in Account object which is lookup to Application object. So I think what you need is to query the Account record instead of Application record. Can you try this code below:
Apex Class
Visualforce
Hope this help you
Thanks for replying back. No the 'Congressional Distrcit' field is on 'Application' object and it is a lookup field to Account.