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

        menu__c m=new menu__c();
        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">
                Name of pizza= <apex:inputfield value="{!pizza_name}"/>
               Price= <apex:inputfield value="{!price}"/>


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.

| improve this answer | |

You cannot bind a class level variable to <apex:inputField>, as input field requires additional meta-data information like label name, data type etc which your class level variable does not have.

You can use <apex:inputText> instead and get those values in controller to build you Menu record. Or else, you can have a Menu instance created and then you can bind fields of Menu directly to <apex:inputField>

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.