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
Narinder Singh 1Narinder Singh 1 

{!input}'. can only be used with SObjects, or objects that are Visualforce field component resolvable

Hello,

My component code is
 
<apex:component >
<apex:attribute name="label" description="" type="String" required="true"/>
<apex:attribute name="input" description="" type="sObject" required="true"/>
<div class="form-group col-md-6">
  <label for="input" class="col-md-2 control-label">{!label}</label>
  <div class="col-md-6 form-control-wrapper">
    <apex:inputField styleClass="form-control" id="input" value="{!input}" />
    <span class="material-input"></span>
  </div>
</div>
</apex:component>
When I use this, I get this error

Error: Could not resolve the entity from value binding '{!input}'. can only be used with SObjects, or objects that are Visualforce field component resolvable.

What binding am I missing?
 
Best Answer chosen by Narinder Singh 1
Gaurav KheterpalGaurav Kheterpal
As the error message itself suggests, the problem here is that your <apex:inputField> is not really associated with any valid field in sObject.

Try changing your code to something along these lines and it should work.
 
<apex:component>
    <apex:attribute name="MyObj" type="sObject" description=""/>
    <apex:attribute name="MyObjField" type="String" description=""/>
    <apex:inputField value="{!MyObj[MyObjField]}"/>
</apex:component>
If my answer helps resolve your query, please select it as a 'Best Answer' so that it benefits others and helps us improve the overall quality of the forums.
 

All Answers

Gaurav KheterpalGaurav Kheterpal
As the error message itself suggests, the problem here is that your <apex:inputField> is not really associated with any valid field in sObject.

Try changing your code to something along these lines and it should work.
 
<apex:component>
    <apex:attribute name="MyObj" type="sObject" description=""/>
    <apex:attribute name="MyObjField" type="String" description=""/>
    <apex:inputField value="{!MyObj[MyObjField]}"/>
</apex:component>
If my answer helps resolve your query, please select it as a 'Best Answer' so that it benefits others and helps us improve the overall quality of the forums.
 
This was selected as the best answer
Bhanu MaheshBhanu Mahesh
Hi Narinder,

Try by changing this line <apex:inputField styleClass="form-control" id="input" value="{!input}" />
to
<apex:inputText styleClass="form-control" id="input" value="{!input}" />

Because <apex:inputField> will bind a sobject field. But here there is no Sobject field. <!input> is not a field.
So use <apex:inputText> to bind <!input>

Regards,
Bhanu Mahesh