I am facing errror when execute this class through vf page and I have to create "create employe" button and redirect to employe page but its not save the company record for create employe button.And same for employe page button save and new, its not save the record.
Please Help.
Company Vf page:
<apex:page standardController="Company__c" extensions="CompanyController">
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:inputField value="{! Company__c.Name}" required="true"/>
<apex:inputField value="{! Company__c.Address__c}" required="true"/>
<apex:inputField value="{! Company__c.Zip_Code__c }" required="true"/>
<apex:inputField value="{! Company__c.State__c}" required="true"/>
<apex:inputField value="{! Company__c.Country__c}" required="true"/>
</apex:pageblockSection>
<apex:pageblockbuttons location="Bottom">
<apex:commandButton action="{! save}" value="Save"/>
</apex:pageblockbuttons>
<apex:pageblockbuttons location="Bottom">
<apex:commandButton action="{! createEmploye}" value="create employee" />
</apex:pageblockbuttons>
</apex:pageblock>
</apex:form>
</apex:page>
employe vf page:
<apex:page standardController="Employe__c" extensions="CompanyController" >
<apex:form >
<apex:pageBlock title="Create Employee">
<apex:pageBlockSection >
<apex:inputField value="{!Employe__c.Name}" rendered="true"/>
<apex:inputField value="{!Employe__c.Company__c}" required="true"/>
<apex:inputField value="{!Employe__c.Email__c}" required="true"/>
<apex:inputField value="{!Employe__c.Employee_Designation__c}" required="true"/>
<apex:inputField value="{!Employe__c.Phone__c}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton action="{! Save}" value="Save" />
</apex:pageBlockButtons>
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton action="{! doSaveAndNew}" value="Save And New" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public class CompanyController{
public List<Company__c> company{set;get;}
public Employe__c employe{set;get;}
public CompanyController(ApexPages.StandardController sc){
}
public PageReference createEmploye(){
company=[Select id,name,Address__c,Country__c,State__c,Zip_Code__c from Company__c];
PageReference pr=new PageReference('/apex/EmployPage');
pr.setRedirect(false);
System.debug(pr);
return pr;
}
public PageReference doSaveAndNew(){
PageReference pr1=new PageReference('/apex/EmployPage');
pr1.setRedirect(true);
System.debug(pr1);
return pr1;
}
}
2 answers
Hi Sakshi,
Here is the error
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{! createEmploye}' in component <apex:commandButton> in page companypage: Class.CompanyController.createEmploye: