You need to sign in to do that
Don't have an account?
Unknown error with visualforce markup
Hi All,
I am new to VisualForce and I am still going through some testing with it to get more familiar. I am making a simple page where the user will enter a contact name and a list of all contacts that match the criteria will be displayed (in a dataTable). I setup my custom controller and wrote some VF markup for the page but I am getting the following error:
Error: Could not resolve the entity from <apex:inputField> value binding '{!accountName}'. inputField can only be used with SObject fields.
I'm not sure what this means. My sample code is below. Does anyone have any suggestions?
Custom Controller
public class CardholderVfController { private String accountName; private List<String> accountList; private String contactName; private List<String> contactList; private final Case c; //public CardholderVfController(ApexPages.StandardController stdController) //{ //this.c = (Case)stdController.getRecord(); //accountList = new List<String>(new String[] {'Test1', 'Test2'}); //} public List<String> getAccounts() { accountList = new List<String>(new String[] {'TestAccountText1', 'TestAccountText2'}); return this.accountList; } public List<String> getContacts() { return this.contactList; } public void setAccountName(String s) { accountName = s; } public String getAccountName() { return this.accountName; } }
Page Markup
<apex:page controller="CardholderVfController"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:inputField id="accountNameField" value="{!accountName}"/> <apex:commandButton id="findAccount" title="Search"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:dataTable align="center" value="{!accounts}" var="a" > <apex:column value="{!a}"/> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> {!accounts[0]} </apex:form> </apex:page>
Hi Dave,
I have come across such problems.
So whenever you are using the <apex:inputField> on visual force page. It expects the tag to be bound with some object (Custom objects or standard objects) not with the local class variables.
So in your code instead of binding the inputField to accountName, bind it to some object. so here is the code you should use :
All Answers
Hi Dave,
I have come across such problems.
So whenever you are using the <apex:inputField> on visual force page. It expects the tag to be bound with some object (Custom objects or standard objects) not with the local class variables.
So in your code instead of binding the inputField to accountName, bind it to some object. so here is the code you should use :
Hi Dave,
The <apex:inputField /> must reference an sObject meaning a Salesforce.com object not a propoerty of your class. What you would want to use is
<apex:inputText id="accountNameField" value="{!accountName}"/>
To use inputField you would have to use the following: <apex:inputField id="accountNameField" value="{!account.Name}"/>
This would return the Name of the Account referenced by your standard Controller.
Hope that helps?
sfdc guy
That did the trick! Thanks a lot guys.