function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Lookup field for non-Sobject field



I have created an Apex class called relation. It has a public field of type contact. I want to input this contact from a VF page.

When I add 

<apex:inputField value="{!}"

 I get this exception:

<apex:inputField> can only be used with SObject fields.	

I added a public contact field in my controller called C.

I tried to use the contact from my controller but again got the same error.


Why is lookup bounded to SObject fields and not SObject types?

Best Answer chosen by Admin (Salesforce Developers) 
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

its work for me

Page :



<apex:page controller="CommunityTestPageController">
    <apex:form >
        <apex:pageBlock id="thePageBlock">
            Select User:<apex:inputfield value="{!myOpportunity.accountid}"/>              
              <apex:commandButton value="Go!" title="Query" action="{!Query}"/>
        <apex:inputfield value="{!accounts.industry}"/>
        <apex:inputfield value="{!contact.LeadSource }"/>


Class :



public class CommunityTestPageController
    public Opportunity myOpportunity  {
       get {
          if (myOpportunity  == null)
             myOpportunity  = new Opportunity ();
          return myOpportunity;
    public Account accounts{
       get {
          if (accounts== null)
             accounts= new Account ();
          return accounts;
    public Contact contact{
       get {
          if (contact== null)
             contact= new Contact ();
          return contact;
    public PageReference Query()
        return null ;