You need to sign in to do that
Don't have an account?
chanti k
How to resolve the System.NullPointerException: Attempt to de-reference a null object
Hello all,
While saving a record now i am getting beloww error on command button , kindly do the needful.
Here i have attached the my code. pls see attached screen shot
Thanks,
Chanti
While saving a record now i am getting beloww error on command button , kindly do the needful.
Here i have attached the my code. pls see attached screen shot
Thanks,
Chanti
Apex class :Public class employmenthistiry { public Employee__c emp{get;set;} public list<Employee__c > empl{get;set;} public List<SelectOption> Technicaloptions{get;set;} public employmenthistiry() { empl=[select id,name,Date_of_joining__c,Department__c,Desigination__c,Email__c,Employeeid__c,Mobile__c,Office_Phone__c,payslip_lase_sent_date__c,Permanent_cITY__c from Employee__c]; } public PageReference submit() { insert emp; return null; } } PAGE <apex:page controller="employmenthistiry" sidebar="true"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Employe" collapsible="false"> <apex:inputField value="{! emp.Name }"/> <apex:inputField value="{! emp.Date_of_joining__c}"/> <apex:inputField value="{! emp.Department__c}"/> <apex:inputField value="{! emp.Desigination__c}"/> <apex:inputField value="{! emp.Email__c}"/> <apex:inputField value="{! emp.Employeeid__c}"/> <apex:inputField value="{! emp.Mobile__c }"/> <apex:inputField value="{! emp.Office_Phone__c}"/> <apex:inputField value="{! emp.payslip_lase_sent_date__c}"/> <apex:inputField value="{! emp.Technology__c}"/> </apex:pageBlockSection> <apex:pageBlockSection TItle="ADDRESS"> <apex:inputField value="{! emp.Permanent_cITY__c }"/> <apex:inputField value="{! emp.Permanent_State__c}"/> <apex:inputField value="{! emp.PIN_CODE__c}"/> <apex:inputField value="{! emp.Permanent__c}"/> <apex:inputField value="{! emp.Name }"/> <apex:inputField value="{! emp.Village__c}"/> </apex:pageBlockSection> <apex:commandButton value="submit" action="{!submit}" /> </apex:pageBlock> </apex:form> </apex:page>
hi@
chanti k
you are getting error on this line
emp is single record you have create soql with specific id or limit 1
or you have to pass id from
[select id,name,Date_of_joining__c,Department__c,Desigination__c,Email__c,Employeeid__c,Mobile__c,Office_Phone__c,payslip_lase_sent_date__c,Permanent_cITY__c from Employee__c limit1]
or
[select id,name,Date_of_joining__c,Department__c,Desigination__c,Email__c,Employeeid__c,Mobile__c,Office_Phone__c,payslip_lase_sent_date__c,Permanent_cITY__c from Employee__c where id ='rec id'];
on page url you have to put id of a record like you page name is CloseLeadReason
https://c.cs8.visual.force.com/apex/CloseLeadReason?id='00635234244xcd'
00635234244xcd is record if of Employee__c
Apex controller:
vf page
Option 1:
Option 2:
Also note that your SOQL query in above code will hit system limits when there are more that 50k records.
Issue is coming because you did not created the object of emp object in your Apex class and you are querying empl object not emp.
NOTE:-// No need of below code as you are not using same in VF page
Try to update your code like below
Let us know if this will help you
<pre>
<apex:page standardController="Employee__c" sidebar="true">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Employee" collapsible="false">
<apex:inputField value="{!Employee__c.Name }"/>
<apex:inputField value="{!Employee__c.Date_of_joining__c}"/>
<apex:inputField value="{!Employee__c.Department__c}"/>
<apex:inputField value="{!Employee__c.Desigination__c}"/>
<apex:inputField value="{!Employee__c.Email__c}"/>
<apex:inputField value="{!Employee__c.Employeeid__c}"/>
<apex:inputField value="{!Employee__c.Mobile__c }"/>
<apex:inputField value="{!Employee__c.Office_Phone__c}"/>
<apex:inputField value="{!Employee__c.payslip_lase_sent_date__c}"/>
<apex:inputField value="{!Employee__c.Technology__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection TItle="Address">
<apex:inputField value="{!Employee__c.Permanent_City__c }"/>
<apex:inputField value="{!Employee__c.Permanent_State__c}"/>
<apex:inputField value="{!Employee__c.PIN_CODE__c}"/>
<apex:inputField value="{!Employee__c.Permanent__c}"/>
<apex:inputField value="{!Employee__c.Name }"/>
<apex:inputField value="{!Employee__c.Village__c}"/>
</apex:pageBlockSection>
<apex:commandButton value="Submit" action="{!save}" />
</apex:pageBlock>
</apex:form>
</apex:page>
</pre>