+ Start a Discussion
cignuscignus 

Lookup field for non-Sobject field

Hi

 

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="{!relation.contact}"

 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:pageBlock>
        <apex:inputfield value="{!accounts.industry}"/>
        <apex:inputfield value="{!contact.LeadSource }"/>
    </apex:form>
</apex:page>

 

Class :

 

 

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