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
nandy.33nandy.33 

outputField can only be used with SObject fields.

 

<apex:page Controller="MyApp" >
    <!-- Begin Default Content REMOVE THIS -->
    <h1>Congratulations</h1>
  This is your new Page: MyApp
  <!-- End Default Content REMOVE THIS -->
    <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>

 

 

 

 

 

public class MyApp {

    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()
    {
    }
}

 

 

When I use this code,   it will alert me.

 

Error: Could not resolve the entity from <apex:inputField> value binding '{!accounts.industry}'. inputField can only be used with SObject fields.

 

but if I delete 

  <apex:inputfield value="{!accounts.industry}"/>

this code, everything is ok.    why?

 

 

Ankit AroraAnkit Arora

Following code worked 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 ;
    }
    
}

 

 

 

 

I don't think there is any problem in your code. Please explore more.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

devfredevfre

Hi i tried with the getter setter method as above for a custom object. But when i'm entering the value in those fields in VF page and trying to pass it to the apex controller, it is not showing the entered values instead it is showing null value in debug. Please let me know what i have to do?

bharathipriya123bharathipriya123

That's because the retun type for the action GO is null. Please write some functionality for the method GO.