• Tina Hadari
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
So I have a set of three visual force pages. Each is a pageblock table showing results from custom controller that is limiting based on parameters passed from commandlinks on the previous pages. One of the limiting parameters is a datetime, however when I pass the parameter to the controller it comes out as a string. Either I am converting this somewhere (can the list<object> handle datetime fields?) or the visualforce page is converting the datetime field to a string that looks like this:

Fri Nov 30 21:55:38 GMT 2012

And I need to either cast this back into a datetime variable or figure out how to pass it as a datetime. Any help that could be provided would be really appreciated! 

 Here is my controller:
 
public with sharing class attendance_class_joins {

    // an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}
    // the object being referenced via url
    //private Lesson__c lesson {get; set;}
    // the variable getting set from the command button 
    public String className {get; set;}
    public String classTimeStr {get; set;}
    //public DateTime ClassTime {get; set;}
    
    
    //---------------------------------------------------------------------
    //Create list for student attendance of all active classes 
    //by using SOQL (seriously salesforce?) to generate list
    
    public ApexPages.StandardSetController activeclassList {
       get {
            if(activeclassList == null) {
                activeclassList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name, Teacher__r.name 
                                              FROM Lesson__c 
                                              WHERE Inactive_lesson__c = False]));
            }
            return activeclassList;
        }
        set;
    }
    
    // Initialize setCon and return a list of records
    public List<Lesson__c> getActiveClasses() {
        return (List<Lesson__c>) activeClassList.getRecords();
    }
    
    
    // handle the action of the commandButton
    public PageReference processLinkClickSA() {
        System.debug('className: '+className);
        return page.lessonselection;
        //Now do something
    	 //go to page http://cs16.salesforce.com/apex/lessonselection
        //return null;
    }
    //------------------------------------------------------------------
    //Create the list for the lesson selection page.
    
    public ApexPages.StandardSetController classtimeList {
       get {
            if(classtimeList == null) {
                classtimeList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name, Date_Time__c 
                                              FROM Lesson_Attendance__c 
                                              WHERE Lesson_ID__r.Name in (:className)
                                              AND Attendance__c = Null]));
            }
            return classtimeList;
        }
        set;
    }
    
    // Initialize setCon and return a list of records
    public List<Lesson_Attendance__c> getClassTimes() {
        return (List<Lesson_Attendance__c>) classtimeList.getRecords();
    }
    
    // handle the action of the commandButton
    public PageReference processLinkClickLS() {
        System.debug('className: '+className);
        //datetime classTime = DateTime.parse(classTimeStr);
        return page.takeroll;
    	 //Now do something
    	 //go to page http://cs16.salesforce.com/apex/lessonselection
        //return null;
    }
    
    //---------------------------------------------------------
    
    //serialize the date/time function gotten on the last page. 
    //datetime classTime = DateTime.parse(classTimeStr);
    //public DateTime classTimeStr() {
    //datetime classTime = ApexPages.currentPage().getParameters().get('classTimeStr');
    //return (DateTime)Json.deserialize(classTimeStr, DateTime.class);
	//}
    //Create the list for the take roll page
 	public ApexPages.StandardSetController rollcallList {
       get {
            if(rollcallList == null) {
                rollcallList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Student_ID__r.Name, Attendance__c, Notes__c 
                                              FROM Lesson_Attendance__c
                                              WHERE Lesson_ID__r.Name in (:className)]));
                                              	//AND Date_Time__c = :classTime]));
            }
            return rollcallList;
        }
        set;
    }
    
    // Initialize Roll call and return a list of records from the above query.
    public List<Lesson_Attendance__c> RollCall {get {
        return (List<Lesson_Attendance__c>) RollCallList.getRecords();
    }}
    
    //Custom save functionality.
    public PageReference save() {
        update RollCall;
        return page.Test_Page;
    }

}
And here are my visual force pages
 
<apex:page controller="attendance_class_joins">
  <h1>Student Attendance</h1>
  <h1>Student Attendance</h1>
  <body>This is where you can take roll and check students attendance records.</body>
  <body>Please select the class series you would like to take attendance for: </body>
      
      <apex:form >
     <apex:pageBlock title="List of Active Classes">
          <apex:pageBlockSection columns="1" >
              <apex:pageBlockTable value="{!ActiveClasses}" var="c">
                  <apex:column headerValue="Lesson Name">
                      <apex:outputText value="{!c.Name}"/>
                  </apex:column>
                  <apex:column headerValue="Teacher">
                      <apex:outputText value="{!c.Teacher__r.Name}"/>
                  </apex:column>
                  <apex:column headerValue="Choose Class">
                  	<apex:commandLink value="Next" action="{!processLinkClickSA}">
                        <apex:param name="classNameParam"
                                    value="{!c.Name}"
                                    assignTo="{!className}"/>
                  </apex:commandLink>
                  </apex:column>
                </apex:pageBlockTable>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>


</apex:page>




<apex:page controller="attendance_class_joins">
  <h1>Class Selection</h1>
  <body>Select the individual meeting of {!className} that you would like to take attendance for:</body>
      <apex:Form >
    	<apex:pageBlock title="List of {!className} Sessions">
          <apex:pageBlockSection columns="1" >
              <apex:pageBlockTable value="{!ClassTimes}" var="d">
                  <apex:column headerValue="Date/Time">
                      <apex:outputText value="{0,date,yyyy-MM-dd HH:mm:ss}">
                          <apex:param value="{!d.Date_Time__c}"/>
                          </apex:outputText>
                  </apex:column>
              		<apex:column headerValue="Choose Class">
                  		<apex:commandLink value="Next" action="{!processLinkClickLS}">
                        	<apex:param name="classTimeParam"
                                        value="{!d.Date_Time__c}"
                                		assignTo="{!classTimeStr}"/>
                  		</apex:commandLink>
                  	</apex:column>  
              </apex:pageBlockTable>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:Form>
</apex:page>


<apex:page controller="attendance_class_joins">
    <h1>
        Take roll call, select the correct attendance value from the dropdown for each student and add notes where appropriate. Then click save to commit.
    </h1>
    <apex:form >
        <apex:pageBlock title="Roll Call" >
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save"
                                    action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!rollcall}" var="stud">
                <apex:column headerValue="Student">
                    <apex:outputText value="{!stud.Student_ID__r.Name}"/>
                </apex:column>
                <apex:column headerValue="Attended?">
                    <apex:inputField value="{!stud.Attendance__c}"/>
                </apex:column>
                <apex:column headerValue="Notes">
                    <apex:inputField value="{!stud.Notes__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>




 
So  I have a visual force page with a page block table that when a user makes a selection it passes the date time from the page to the controller that uses it in a query. However the parameter is passing the date time in the following format:

Fri Nov 30 21:55:38 GMT 2012

and I can't seem to figure out how to put it back into the format the database seems to use:

"2014-01-24T16:56:27.044Z"

Is there an easy way to perform this conversion or to adjust my query to accept the parsed out date time value? 


 
So I have a set of three visual force pages. Each is a pageblock table showing results from custom controller that is limiting based on parameters passed from commandlinks on the previous pages. One of the limiting parameters is a datetime, however when I pass the parameter to the controller it comes out as a string. Either I am converting this somewhere (can the list<object> handle datetime fields?) or the visualforce page is converting the datetime field to a string that looks like this:

Fri Nov 30 21:55:38 GMT 2012

And I need to either cast this back into a datetime variable or figure out how to pass it as a datetime. Any help that could be provided would be really appreciated! 

 Here is my controller:
 
public with sharing class attendance_class_joins {

    // an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}
    // the object being referenced via url
    //private Lesson__c lesson {get; set;}
    // the variable getting set from the command button 
    public String className {get; set;}
    public String classTimeStr {get; set;}
    //public DateTime ClassTime {get; set;}
    
    
    //---------------------------------------------------------------------
    //Create list for student attendance of all active classes 
    //by using SOQL (seriously salesforce?) to generate list
    
    public ApexPages.StandardSetController activeclassList {
       get {
            if(activeclassList == null) {
                activeclassList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name, Teacher__r.name 
                                              FROM Lesson__c 
                                              WHERE Inactive_lesson__c = False]));
            }
            return activeclassList;
        }
        set;
    }
    
    // Initialize setCon and return a list of records
    public List<Lesson__c> getActiveClasses() {
        return (List<Lesson__c>) activeClassList.getRecords();
    }
    
    
    // handle the action of the commandButton
    public PageReference processLinkClickSA() {
        System.debug('className: '+className);
        return page.lessonselection;
        //Now do something
    	 //go to page http://cs16.salesforce.com/apex/lessonselection
        //return null;
    }
    //------------------------------------------------------------------
    //Create the list for the lesson selection page.
    
    public ApexPages.StandardSetController classtimeList {
       get {
            if(classtimeList == null) {
                classtimeList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name, Date_Time__c 
                                              FROM Lesson_Attendance__c 
                                              WHERE Lesson_ID__r.Name in (:className)
                                              AND Attendance__c = Null]));
            }
            return classtimeList;
        }
        set;
    }
    
    // Initialize setCon and return a list of records
    public List<Lesson_Attendance__c> getClassTimes() {
        return (List<Lesson_Attendance__c>) classtimeList.getRecords();
    }
    
    // handle the action of the commandButton
    public PageReference processLinkClickLS() {
        System.debug('className: '+className);
        //datetime classTime = DateTime.parse(classTimeStr);
        return page.takeroll;
    	 //Now do something
    	 //go to page http://cs16.salesforce.com/apex/lessonselection
        //return null;
    }
    
    //---------------------------------------------------------
    
    //serialize the date/time function gotten on the last page. 
    //datetime classTime = DateTime.parse(classTimeStr);
    //public DateTime classTimeStr() {
    //datetime classTime = ApexPages.currentPage().getParameters().get('classTimeStr');
    //return (DateTime)Json.deserialize(classTimeStr, DateTime.class);
	//}
    //Create the list for the take roll page
 	public ApexPages.StandardSetController rollcallList {
       get {
            if(rollcallList == null) {
                rollcallList = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Student_ID__r.Name, Attendance__c, Notes__c 
                                              FROM Lesson_Attendance__c
                                              WHERE Lesson_ID__r.Name in (:className)]));
                                              	//AND Date_Time__c = :classTime]));
            }
            return rollcallList;
        }
        set;
    }
    
    // Initialize Roll call and return a list of records from the above query.
    public List<Lesson_Attendance__c> RollCall {get {
        return (List<Lesson_Attendance__c>) RollCallList.getRecords();
    }}
    
    //Custom save functionality.
    public PageReference save() {
        update RollCall;
        return page.Test_Page;
    }

}
And here are my visual force pages
 
<apex:page controller="attendance_class_joins">
  <h1>Student Attendance</h1>
  <h1>Student Attendance</h1>
  <body>This is where you can take roll and check students attendance records.</body>
  <body>Please select the class series you would like to take attendance for: </body>
      
      <apex:form >
     <apex:pageBlock title="List of Active Classes">
          <apex:pageBlockSection columns="1" >
              <apex:pageBlockTable value="{!ActiveClasses}" var="c">
                  <apex:column headerValue="Lesson Name">
                      <apex:outputText value="{!c.Name}"/>
                  </apex:column>
                  <apex:column headerValue="Teacher">
                      <apex:outputText value="{!c.Teacher__r.Name}"/>
                  </apex:column>
                  <apex:column headerValue="Choose Class">
                  	<apex:commandLink value="Next" action="{!processLinkClickSA}">
                        <apex:param name="classNameParam"
                                    value="{!c.Name}"
                                    assignTo="{!className}"/>
                  </apex:commandLink>
                  </apex:column>
                </apex:pageBlockTable>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>


</apex:page>




<apex:page controller="attendance_class_joins">
  <h1>Class Selection</h1>
  <body>Select the individual meeting of {!className} that you would like to take attendance for:</body>
      <apex:Form >
    	<apex:pageBlock title="List of {!className} Sessions">
          <apex:pageBlockSection columns="1" >
              <apex:pageBlockTable value="{!ClassTimes}" var="d">
                  <apex:column headerValue="Date/Time">
                      <apex:outputText value="{0,date,yyyy-MM-dd HH:mm:ss}">
                          <apex:param value="{!d.Date_Time__c}"/>
                          </apex:outputText>
                  </apex:column>
              		<apex:column headerValue="Choose Class">
                  		<apex:commandLink value="Next" action="{!processLinkClickLS}">
                        	<apex:param name="classTimeParam"
                                        value="{!d.Date_Time__c}"
                                		assignTo="{!classTimeStr}"/>
                  		</apex:commandLink>
                  	</apex:column>  
              </apex:pageBlockTable>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:Form>
</apex:page>


<apex:page controller="attendance_class_joins">
    <h1>
        Take roll call, select the correct attendance value from the dropdown for each student and add notes where appropriate. Then click save to commit.
    </h1>
    <apex:form >
        <apex:pageBlock title="Roll Call" >
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save"
                                    action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!rollcall}" var="stud">
                <apex:column headerValue="Student">
                    <apex:outputText value="{!stud.Student_ID__r.Name}"/>
                </apex:column>
                <apex:column headerValue="Attended?">
                    <apex:inputField value="{!stud.Attendance__c}"/>
                </apex:column>
                <apex:column headerValue="Notes">
                    <apex:inputField value="{!stud.Notes__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>