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
Gulshan__cGulshan__c 

Unknown property 'InsertByVF.Position__c

Hi getting the exception when trying to add records on my custom object Position__c

Here is my Controller :


public class InsertByVF{

    public Position__c pos;
    public String positionName{get;set;}
    public Decimal MinimumPay{get;set;}
    public Decimal MaximumPay{get;set;}
    
    public InsertByVF()
    {
    pos=new Position__c();
    
    }
  
    public void doInsert()
    {
 
    pos.Name=positionName;
    pos.Max_Pay__c=MaximumPay;
    pos.Min_Pay__c=MinimumPay;
       
  insert pos;      
       
 }
}


And below is my Apex page code :

<apex:page controller="InsertByVF">
<apex:form >
<apex:pageBlock title="New Position">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel >Position Name :</apex:outputLabel>
<apex:inputField id="FirstName" value="{!Position__c.positionName}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Max Pay :</apex:outputLabel>
<apex:inputField id="MaxPay" value="{!Position__c.MaximumPay}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Min Pay :</apex:outputLabel>
<apex:inputField id="MinPay" value="{!Position__c.MinimumPay}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton id="Save" action="{!doInsert}" value="Save"/>
<!--<apex:commandButton id="Cancel" action="{!Cancel}" value="Cancel"/>-->
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Best Answer chosen by Gulshan__c
Marek Kosar_Marek Kosar_
Hi gulshan,

your VF page -->
<apex:page controller="InsertByVF">
<apex:form >
<apex:pageBlock title="New Position">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel >Position Name :</apex:outputLabel>
<apex:inputField id="FirstName" value="{!positionName}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Max Pay :</apex:outputLabel>
<apex:inputField id="MaxPay" value="{!MaximumPay}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Min Pay :</apex:outputLabel>
<apex:inputField id="MinPay" value="{!MinimumPay}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton id="Save" action="{!doInsert}" value="Save"/>
<!--<apex:commandButton id="Cancel" action="{!Cancel}" value="Cancel"/>-->
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

All Answers

Marek Kosar_Marek Kosar_
Hi gulshan,

your VF page -->
<apex:page controller="InsertByVF">
<apex:form >
<apex:pageBlock title="New Position">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel >Position Name :</apex:outputLabel>
<apex:inputField id="FirstName" value="{!positionName}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Max Pay :</apex:outputLabel>
<apex:inputField id="MaxPay" value="{!MaximumPay}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Min Pay :</apex:outputLabel>
<apex:inputField id="MinPay" value="{!MinimumPay}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton id="Save" action="{!doInsert}" value="Save"/>
<!--<apex:commandButton id="Cancel" action="{!Cancel}" value="Cancel"/>-->
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 
This was selected as the best answer
Gulshan__cGulshan__c
Thank you Marek for your quick reply..
Gulshan__cGulshan__c
tried it..Still not working..got error as :

Error: Could not resolve the entity from <apex:inputField> value binding '{!positionName}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
Marek Kosar_Marek Kosar_
hi gulshan,

right, you can use <apex:inputField to set only sObject fields.
Use <apex:input, with attribute type (text, number): https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_input.htm
Or <apex:inputText : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputText.htm (http://​https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputText.htm)
Gulshan__cGulshan__c

Thanks a lot Marek..Now its working fine...!