+ Start a Discussion
VeniVeni 

Insertion of Data Error

I am new to salesforce, i am creating an application with Apex and Visualforce.

 


when i am trying to insert data in custom object, i get Null Pointer Exception, can some one help me, its very urgent.

 

Thanks in Advance

 

My Code:

 

Visualforce:

 

<apex:form id="MyFirstform">

  <apex:pageBlock >

      <apex:pageBlockButtons >

          <apex:commandButton action="{!save}" value="Save"/>   

          <apex:commandButton action="{!cancel}" value="Cancel"/>

      </apex:pageBlockButtons>

      

      <apex:pageBlockSection title="Customer Information" id="informationid" columns="2">

         

         <apex:outputLabel value="Customer Id: " style="font-weight:bold"></apex:outputLabel>

         

         <apex:inputText id="custid" />

         

         <apex:outputLabel value="SSN/Tax ID/Customer Number: " style="font-weight:bold"></apex:outputLabel>

         <apex:inputText id="ssn"/>

         <apex:outputLabel value="Name: " style="font-weight:bold"></apex:outputLabel>

         <apex:inputText id="name"/>

         <apex:outputLabel value="Phone/Cell Number: " style="font-weight:bold"></apex:outputLabel>

         <apex:inputText id="cell"/>

         <apex:outputLabel value="Address: " style="font-weight:bold"></apex:outputLabel>

         <apex:inputText id="address"/>

         <apex:outputLabel value="Email Address: " style="font-weight:bold"></apex:outputLabel>

         <apex:inputText id="email"/>

     </apex:pageBlockSection>

     

     <apex:pageBlockSection title="Caller Information" id="callerinformid">

         <apex:outputLabel value="Is Caller: "></apex:outputLabel>

         <input type="checkbox" id="check" onclick="jsvalidate()"/>

         

         <apex:outputLabel value="Caller Name: "></apex:outputLabel>

         <input type="text" id="callername"/>

         <apex:outputLabel value="Relation Type: "></apex:outputLabel>

         <select id="relationtype">

         <option value="Select">--Select--</option>

         <option value="Service">Service</option>

        <option value="Move In">Move In</option>

        <option value="Move Out">Move Out</option>

        <option value="Transfer">Transfer</option>

         </select>

     </apex:pageBlockSection>

   

    <apex:pageBlockSection title="New Permises / Contract Number" id="contractnum">

         <apex:outputLabel value="Contract Number: "></apex:outputLabel>

         <apex:inputText id="contractnumber"/>

    </apex:pageBlockSection>

    

    <apex:pageBlockSection title="Services and Dates" id="servdate">

         <apex:outputLabel value="Electricity Permit Required "></apex:outputLabel>

          <input type="checkbox" id="permit" onclick="jsvalidate1()"/>

         <apex:outputLabel value="Turn On All "></apex:outputLabel>

         <input type="checkbox" id="all" onclick="jsvalidate2()"/>

         <apex:outputLabel value="Turn Electricity "></apex:outputLabel>

          <input type="checkbox" id="electric" onclick="jsvalidate2()"/>

         <apex:outputLabel value="Turn Lighting "></apex:outputLabel>

          <input type="checkbox" id="light" onclick="jsvalidate2()"/>

         

         <apex:outputLabel value="Service Start Date"></apex:outputLabel>

            <input type="text" id="servdate"/>

         <apex:outputLabel value="Meter Number"></apex:outputLabel>

         <input type="text" id="meternum"/>

         <apex:outputLabel value="Rate"></apex:outputLabel>

         <input type="text" id="rate"/>

         <apex:outputLabel value="Remarks"></apex:outputLabel>

         <apex:inputText id="remark"/>

         

    </apex:pageBlockSection>

    

    

</apex:pageBlock>

  </apex:form>  

 

 

 

Apex:

 

public class UCIP {

 

    public PageReference cancel() {

        return null;

    }

 

 

    

    private String id{ get; set; }

    private  Integer custid{ get; set; }

    private  Integer ssn{ get; set; }

    private String name{ get; set; }

    private String cell{ get; set; }

    private String address{ get; set; }

    private String email{ get; set; }

    private Integer contractnumber{ get; set; }

    private String callername{ get; set; }

    private String relationtype{ get; set; }

    private Date servstdate{ get; set; }

    private Integer meternum{ get; set; }

    private Integer rate{ get; set; }

    private String remks{ get; set; }

           

       public PageReference save() {

       Map<string,string> postParameters = ApexPages.currentPage().getParameters();

 

        try{

          

          

          UCIP__c obj= new UCIP__c();

 

 

 

          obj.CustomerId__c = Decimal.valueOf(postParameters.get('custid1'));

          obj.SSN_Tax_ID_Customer_Number__c = Integer.valueOf(postParameters.get('ssn'));

          obj.Name__c = postParameters.get('name');

          obj.Phone_Cell_Number__c = postParameters.get('cell');

          obj.Address__c = postParameters.get('address');

          obj.Email_Address__c = postParameters.get('email');

          obj.Rate__c = Integer.valueOf(postParameters.get('rate'));

          insert obj;

          System.debug('Success');

         

        }catch(System.DmlException e){

            System.debug(e);

 

        }

        

        String newPageUrl = '/apex/ordercontract';

        PageReference newPage = new PageReference(newPageUrl);

        newPage.setRedirect(true);

        return newPage;

   }

    

Best Answer chosen by Admin (Salesforce Developers) 
gm_sfdc_powerdegm_sfdc_powerde

This is not the right way to read parameters while using command button to bind your action.  All your inputText tags should use value attribute to bind the value to properties in your controller.  For instance,

 

<apex:inputText value="{!email}" id="email"/>

 

Also, make sure that your properties are public first for the value bindings to work.

 

 

All Answers

gm_sfdc_powerdegm_sfdc_powerde

This is not the right way to read parameters while using command button to bind your action.  All your inputText tags should use value attribute to bind the value to properties in your controller.  For instance,

 

<apex:inputText value="{!email}" id="email"/>

 

Also, make sure that your properties are public first for the value bindings to work.

 

 

This was selected as the best answer
VeniVeni

Thanks , It works.

 

Can i also know how to retrive the data from drop down and check box

gm_sfdc_powerdegm_sfdc_powerde
If you bind your custom object directly, you can use apex:inputField tag and visualforce will take care of rendering the field according to its type (picklist, checkbox, text etc)