[SalesForce] Apex InputField value binding error

Why I will get all the time this error?

Could not resolve the entity from value binding
'{!order.test}'. <apex:inputField> can only be used with SObjects, or
objects that are Visualforce field component resolvable.

OrderItem – Class:

public with sharing class OrderItem {

  public OrderItem(){
    this(null);
  }

  public OrderItem(String contactId){
    this.contactId = contactID;
  }

  public String test = 'test';
}

Contact – Extension Class

public with sharing class ExtendedContact {

public Contact contact {get; set;}

 public OrderItem order {
  get {
      if (order == null)
        order = new OrderItem();
      return order;
    }
  set;
  }
}

Page:

<apex:page standardController="Contact" extensions="ExtendedContact">
<apex:form >
  <apex:pageMessages />
  <apex:detail relatedList="true"/>
  <apex:pageblock title="ExtendedContact">
    <apex:pageBlockSection title="Title" columns="1">
    <apex:inputField value="{!order.test}" 
                    label="greetText" 
                    style="width:300px; height:100px" required="TRUE"/>
    </apex:pageBlockSection>
  </apex:pageblock>
</apex:form>
</apex:page>

Thanks for any help.

Best Answer

I think there are two issues:

  • apex:inputField can only bind to an SObject field (as it takes the type and label from the field metadata) but you are trying to bind it to a String; use apex:inputText instead
  • you have not provided get/set methods for OrderItem.test; one way to accomplish this is to change the code to initialise in the constructor and then use a public String test {get; set;} Apex Property
Related Topic