+ Start a Discussion
Khalid AbdullahKhalid Abdullah 

How to pull proper date in VisualForce from Events

Hello all,

We have an apex class which updates a field called "Next Meeting Date" on Contacts based on the activities related to contact records
The class updates this field with the Activity date of the meeting nearest in the future.

We also have a visualforce page which is pulling the next meeting date information from the activity records and providing the information from each activity in the future for that contact on the top of the contact's page.

However, when the "All Day Event" field is selected on the activity, the visualforce page is pulling the UTC date, which is resulting in the VF section showing the incorrect date while the "Next Meeting Date" field is showing correctly.

Tl;Dr - how do I adjust the visualforce page to pull the correct time zone date when the "All Day Event" field is selected? Or do I need to manipulate the logic directly in the apex class for this to work. We would need to add 1 day to the StartDateTime and EndDateTime fields.

VisualForce code: 
<apex:page standardController="Contact" extensions="UpcomingMeetings" sidebar="false" showHeader="false">
    <style type="text/css">
    .meetingToday {
//        font-weight:bold;

    <apex:pageMessage severity="INFO" strength="1" summary="{!summary}" escape="false">
        <apex:dataTable value="{!events}" var="e" width="100%" cellpadding="1" cellspacing="1" rows="3">
            <apex:column >
            <apex:column >
                <apex:outputLink value="/{!e.Id}" target="_blank" styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}"><apex:outputField value="{!e.Subject}"/></apex:outputLink>
            <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}">
                <apex:outputText value="from"/>
            <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}">
                <apex:outputField value="{!e.StartDateTime}"/>
            <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}">
                <apex:outputText value="to"/>
            <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}">
                <apex:outputField value="{!e.EndDateTime}"/>

Apex class used for VisualForce page:
public with sharing class UpcomingMeetings {
    public List<Event> events { get; private set; }    
    public String summary { get; private set; }
    public String riaAdvisor { get; private set; }
    public UpcomingMeetings(ApexPages.StandardController controller) {
        Id contactId = controller.getRecord().Id;   
       system.debug('Contact id ---'+ contactId);
       Contact c = [SELECT id,Is_RIA_Advisor__c,RIA_Wholesaler_Name__c from Contact where Id=:contactId];
       if (c.Is_RIA_Advisor__c)
          riaAdvisor = 'This is a RIA contact. Please direct all calls to '+c.RIA_Wholesaler_Name__c+'<br/>';

        events = new List<Event>();
        try {
            Set<Id> eventIds = new Set<Id>();
            for (EventRelation e : [SELECT EventId FROM EventRelation  WHERE RelationId =:contactId AND Status NOT IN ('Declined','Uninvited')]) {
            events = [SELECT Id, Subject, StartDateTime, EndDateTime FROM Event WHERE (WhoId=:contactId OR Id IN :eventIds) AND Event.Cancelled__c <> TRUE AND ActivityDate>=TODAY ORDER BY ActivityDate ASC];
            if (events.isEmpty()) {
                summary = riaAdvisor +'You have no upcoming meetings scheduled'; 
            } else {
                summary = riaAdvisor +'Upcoming meetings';
        } catch (Exception e) {

Matthew CokeMatthew Coke
i would suggest that you just make your life easy and update the logic in the controller directly :)