1

I just created a new object variable to student__c and tried to insert the record with the values received from VF page i.e. when i clicked on the submit button, it has not shown any error message. But when i checked the tab in the app with my custom object Student__c, there is no records is inserted with the process i have done below. Please help this processed.

apex class:

public class ProcessAdmission {

    private ApexPages.StandardController controller;
    public String StdFName{get; set;}
    public String StdLName{get; set;}
    public String StdMName{get; set;}
    public String StdFatherName{get; set;}
    public String StdMotherName{get; set;}
    public Date DOB{get; set;}
    public String email{get; set;}
    public String Mobilenbr{get; set;}
    public String joinClass{get; set;}
    public String address {get; set;}
    public Integer  StudentId {get; set;}
    public String gendervalue{get; set;}
    public Student__c datarecords{get; set;}

    public ProcessAdmission(ApexPages.StandardController cont)
    {
       this.controller = cont;
       datarecords =  new Student__c();       
    }

    public void submit()
    {
        Student__c newRec = new Student__C();
        newRec.Address__c           = address ;
        newRec.Contact_email_Id__c  = Mobilenbr;
        newRec.Date_of_Birth__c     = DOB;
        newRec.Father_Name__c       = StdFatherName;
        newRec.Gender__c            = genderValue;
        newRec.Join_Class__c        = JoinClass;
        newRec.Mobile_number__c     = mobileNbr;
        newRec.Mother_Name__c       = StdmotherName;
        newRec.Student_First_Name__c = StdFName;
        newRec.Student_Last_Name__c  = StdLName;
        newRec.Student_Middle_Name__c = stdMname;

        insert newRec;
    }
}

Visualforce Page:

<apex:page standardController="Student__c" extensions="ProcessAdmission">
    <apex:form >
        <apex:pageBlock >

    <apex:pageBlockSection title="New Student Admission">

                <apex:outputLabel id="inputtxta" value="First Name" for="StdFName"/>
                <apex:inputText id="StdFName" value="{!StdFName}"/>
                <apex:outputLabel id="inputtxtab" value="Middle Name" for="StdMName"/>
                <apex:inputText id="StdMName" value="{!StdMName}"/>
                <apex:outputLabel id="inputtxtb" value="Last Name" for="StdLName"/>
                <apex:inputText id="StdLName" value="{!StdLName}"/>
                <apex:outputLabel id="inputtxtc" value="Father's Name " for="StdFatherName"/>
                <apex:inputText id="StdFatherName" value="{!StdFatherName}"/>
                <apex:outputLabel id="inputtxtd" value="Mother's Name " for="StdMotherName"/>
                <apex:inputText id="StdMotherName" value="{!StdMotherName}"/>
                <apex:outputLabel id="inputtxte" value="Address" for="Stdadress"/>
                <apex:inputText id="StdAdress" value="{!address}"/>
        <apex:outputLabel id="inputtxtf" value="mobile" for="mobile"/>
                <apex:inputText id="mobile" value="{!Mobilenbr}"/>
        <apex:outputLabel id="inputtxtg" value="emailId" for="EmailID"/>
                <apex:inputText id="EmailId" value="{!email}"/>
        <apex:outputLabel id="inputtxth" value="dateofbrith" for="dateofbirth"/>
                <apex:inputText id="dateofbirth" value="{!DOB}"/>

                <apex:outputLabel id="selectLista" value="Gender" for="StdGender"/>
                <apex:selectList id="StdGender" value="{!Gendervalue}" size="1">
                    <apex:selectOption itemValue="Male" itemLabel="male" />
                    <apex:selectOption itemValue="Female" itemLabel="female"/>
                    <apex:selectOption itemValue="Transgender" itemLabel="TansGender"/>
                </apex:selectList>


          <apex:selectList id="StdClass" value="{!JoinClass}" size="1">
                    <apex:selectOption itemValue="V" itemLabel="five" />
                    <apex:selectOption itemValue="VI" itemLabel="six"/>
                    <apex:selectOption itemValue="VII" itemLabel="seven"/>
              <apex:selectOption itemValue="VIII" itemLabel="eigth"/>
              <apex:selectOption itemValue="IX" itemLabel="nine"/>
              <apex:selectOption itemValue="X" itemLabel="ten"/>
                </apex:selectList>
        <apex:outputLabel id="buttonid" value="button" for="validate"/>
              <apex:commandButton id="validate" value="Submit" action="{!submit}"/>
    </apex:pageBlockSection>
            </apex:pageBlock>

        </apex:form>
</apex:page>

1 Answer 1

2

I can't see a good reason for this to fail, but you should add an <apex:pageMessages/> tag to your page to see any errors that might be generated.

That aside, you could make this page and controller far simpler! Instead of creating member variables in the controller for each field, you simply need a public SObject instance, which you have as datarecords, but I'm changing to student since it makes more sense and isn't plural:

public Student__c student get; set;}

Then your page block section could look more like this:

<apex:pageBlockSection title="New Student Admission">
    <apex:inputField value="{!student.First_Name__c}"/>
    <apex:inputField value="{!student.Middle_Name__c}"/>
    <apex:inputField value="{!student.Last_Name__c}"/> 
    ... 

And finally your submit action would look like this:

public void submit()
{
    insert student;
}
3
  • how to select list that i have defined for the custom object. for instance i have gender select list with two values male and female but how do i mention them in the vf page with select options and select list ?
    – Wenky
    Mar 9, 2015 at 17:34
  • when i've used the above as suggested by u, i'm getting error msg like "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields r missing: [Student First Name, Father's Name, Date of Birth, Contact email Id, Mobile number, Address, Student Last Name]: [Student First Name, Father's Name, Dateof Birth, Contact email Id, Mobile number, Address, Student Last Name] Error is in expression '{!submit}' in component <apex:commandButton> in page newadmission_vfx: Class.ProcessAdmission.submit: line 117, column 1" where controller new student__C.
    – Wenky
    Mar 10, 2015 at 2:15
  • That means those fields need to have values in them and haven't been provided. Typically you'd want to use a try {} catch {} block to watch out for errors and then add page messages to display useful errors to the user. If they're on the page however VF should enforce the required field status for you.
    – Matt Lacey
    Mar 11, 2015 at 3:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .