You need to sign in to do that
Don't have an account?
Andrey
NullPointerException de-reference a null object when I try to save
Hi all!
I created vf page and when I try to save a new record, I get an error: "System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!Save}' in component <apex:commandButton> in page te_new".
Can someone tell me, where I'm wrong?
Vf page code:
I created vf page and when I try to save a new record, I get an error: "System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!Save}' in component <apex:commandButton> in page te_new".
Can someone tell me, where I'm wrong?
Vf page code:
<apex:page standardController="Travel_Expenses__c" extensions="TE_Object"> <apex:form > <apex:pageBlock title="Travel Information Edit" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!SaveAndNew}" value="Save & New"/> <apex:commandButton action="{!Cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2" > <apex:pageBlockSectionItem > Travel Information <apex:inputField value="{!NewTE.Traveler__c}" required="true"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > Expense Type <apex:inputField value="{!NewTE.Expense_Type__c}" required="true"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > Amount <apex:inputField value="{!NewTE.Amount__c}" required="true"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > Country <apex:inputField value="{!NewTE.Country__c}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > Inventory Number <apex:inputField value="{!NewTE.Inventory_Number__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > Description <apex:inputField value="{!NewTE.Description__c}" required="true"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>apex class:
public class TE_Object { public Travel_Expenses__c NewTE{get;set;} public TE_Object(ApexPages.StandardController controller) { } public pagereference Save() { try { insert NewTE; //Error message on this line } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } return null; } public pagereference SaveAndNew() { try { insert NewTE; } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } return (new ApexPages.StandardController(new Travel_Expenses__c())).edit(); } }
If this helps,please mark it as best answer to help others :)
All Answers
If this helps,please mark it as best answer to help others :)
Please change your constructor method as below and you should be good.
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank