[SalesForce] Could not resolve the entity from value binding —

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

apex class

public class pizza_menu {
    public string pizza_name{get;set;}
    public integer price{get;set;}
    public void addmenu()
    {
        try

    {
        menu__c m=new menu__c();
        m.name=pizza_name;
        m.price__c=price;
        insert m;

    }

    catch (DmlException e) {
    System.debug('A DML exception has occurred: ' +e.getMessage());
}
    }
}

vf page

<apex:page sidebar="false" controller="pizza_menu">
    <apex:pageBlock title="add the pizza" >
        <apex:pageBlockSection columns="2">
            <apex:form>
                Name of pizza= <apex:inputfield value="{!pizza_name}"/>
               Price= <apex:inputfield value="{!price}"/>
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>

</apex:page>

Best Answer

The <apex:inputField> component must be used with fields on an sObject. You do not have an sObject here, just a primitive instance variable on your controller, so you cannot use this component.

The <apex:inputText> component, and other such input components, can be used with controller instance variables.

Alternately, you can store a Menu__c instance, created in your constructor, within your controller class, and reference its field values directly via <apex:inputField>, as for example {! menu.Name }. Your controller would need to declare

public Menu__c menu { get; set; }

and initialize it in the constructor.

Related Topic