You need to sign in to do that
Don't have an account?
accessing date / datetime fields
Hello,
I have some experience in APEX and Visualforce, but still found issues on developing.
Could someone please give me an advice, how to overwrite the close date on Opportunities?
I have generated a new field on Opportunity, called NewDate__c (Date, Label: "New Close Date"). and a save-button on my ExtensionController.
everytime, when I access the NewDate__c in the method {!overridenewdatetoclosedate}, I receive this exeption:
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.
my VF-PAge is this:
<apex:page standardController="Opportunity" extensions="ClsOppChangeCloseDate" action="{!init}"> <apex:form id="FormChangeCloseDate1"> <apex:pageBlock mode="inlineEdit" id="pb"> <apex:pageBlockSection id="pbs1"> <apex:commandButton action="{!overridenewdatetoclosedate}" value="Save all" id="btnSave" /> </apex:pageBlockSection> <apex:pageBlockSection id="pbs2"> <apex:outputField value="{!opportunity.closeDate}" /> <apex:outputField value="{!opportunity.NewDate__c}" /> </apex:pageBlockSection> <apex:pageBlockSection id="pbs3"> <apex:outputText value="{!oldDate}" /> <apex:outputText value="{!newDate}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
my ExtensionController is this:
public class ClsOppChangeCloseDate { private ApexPages.StandardController stdCtrl; public Datetime oldDate {get; set;} public Datetime newDate {get; set;} public Integer difDate {get; set;} public Opportunity chOpp {get; set;} public ClsOppChangeCloseDate(ApexPages.StandardController std){ stdCtrl=std; } public void init(){ Opportunity chOpp = [SELECT Id, Name, CloseDate, NewDate__c FROM Opportunity WHERE Id = :stdCtrl.getId()]; oldDate = chOpp.CloseDate; newDate = chOpp.NewDate__c; } // end init(); public PageReference overridenewdatetoclosedate(){ newDate = chOpp.NewDate__c; stdCtrl.save(); return null; } public PageReference save() { stdCtrl.save(); return null; } }
any hints are welcome!
You have never set the property chOpp to anything. In the init() method you use a local variable called chOpp instead.
Change that to use the class property chOpp instead and it should work.
All Answers
my wish would be a method like this:
than I can calculate the difference in Days between the datefields and add it to the oppsLineItems.
You have never set the property chOpp to anything. In the init() method you use a local variable called chOpp instead.
Change that to use the class property chOpp instead and it should work.
Thank you! :robothappy: