function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Esther Thomas 2Esther Thomas 2 

assigning datetime custom field value is throwing an exception :(

Hi Everyone,
 I'm trying a simple test
1. passing in a custom field (datetime) from my VF page to my apex controller.
2. take the datetime value passed and reassing it to a new datetime variable
3. convert datetime value in variable to string and have it re-rendered in my pagblocksection

When the action method is called, assigning that custom field datetime value seems to be throwing an exception. Pulling my hair out. Not sure where I've messed this up or misunderstood how this is suppose to work. Thanks in advance! 
 
<apex:page standardController="Booking__c" extensions="testing7">
    <apex:form>
        <apex:pageBlock>
        <apex:pageBlockSection>
            <apex:inputfield value="{!Records.Start_Date_Time__c}">
            <apex:actionSupport action="{!UpdateSitter}" event="onchange" reRender="D1"/>   
            </apex:inputfield>
        </apex:pageBlockSection>
            
        <apex:pageBlockSection columns="1" id="D1">          
            <apex:pageBlockTable value="{!Sdate}" var="sd" rendered="{!FlagH}">
            <apex:column value="{!sd}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

public class testing7 {
    public Booking__c Records{get;set;}
    public String Sdate{get;set;}
    public Datetime DT{get;set;}
    public Boolean FlagH{get;set;}

    public PageReference UpdateSitter(){
        FlagH=true;
        try{ 
            DT = Records.Start_Date_Time__c;  //throwing an exception on this line
            Sdate=String.ValueOf(DT);
           }catch(System.NullPointerException e){
              Sdate='fail';
           }
        return null;
    }
    
    public testing7(ApexPages.StandardController controller)  {}
    
}

 
badibadi
Change 
public testing7(ApexPages.StandardController controller)  {}

to
public testing7(ApexPages.StandardController controller)  {
        Records= (Booking__c)controller.getRecord();
    }

For more information - ​https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardcontroller.htm

Hope this helps
Esther Thomas 2Esther Thomas 2
That was perfect, thank you!
Esther Thomas 2Esther Thomas 2
that worked, thank you so much!