You need to sign in to do that
Don't have an account?
How to create Lookup field in Visualforce - solution found
Hi,
I know that there has already been many discussions about this, but I still could not find a working solution. However, I got it to work, so I would like to share my solution with you.
To create a lookup field in Visualforce, you need <apex:inputField> wrapped in <apex:form>.
The value attribute in <apex:inputField> must reference a real Lookup field. For example, in Contacts there is a standard Lookup field called ReportsTo.
Here is my Visualforce code:
<apex:page standardController="Contact" extensions="SendEmailPageController">
<apex:form>
<apex:inputField value="{!person.ReportsToId}"/>
</apex:form>
Here is the Apex controller (I am overriding a standard controller for a Contact object):
public class SendEmailPageController {
public Contact person {set;}
public Contact getPerson()
{
return [select id, reportstoid from Contact limit 1];
}
}
Hope it helps!
I'm slightly confused as to how this is creating a lookup field in visualforce - this looks like its using the standard inputfield component. You could do this using entirely standard functionality:
All Answers
Good One.
I'm slightly confused as to how this is creating a lookup field in visualforce - this looks like its using the standard inputfield component. You could do this using entirely standard functionality:
HI Bob,
your solution also works AND is much shorter.
Many thanks!