I am trying to display today’s event ina vfpage like Salesforce today event component does, but my query is not resulting in the correct list based on user time zone when putting where clause to today. Rather it is giving the results based on UTC date time stored in the database. Using soql convert timezone method on startdatetime field. like this Day_Only(convertTimezone(StartDateTime))=Today. but I noticed it's not returning the Events according to current user timezone. here is my complete code.
public with sharing class EventExt {
public List<Event> getEvents() {
List<Event> eventList = new List<Event>();
eventList = [SELECT id, subject,format(StartDateTime) from event WHERE (ownerId =:UserInfo.getUserID() and Day_Only(convertTimezone(StartDateTime)) = Today ) limit 10];
return eventList;
} }
<apex:page controller="EventExt" >
<apex:pageBlock >
<apex:pageBlockTable value="{!Events}" var="event">
<apex:column value="{!event.subject}"/>
<apex:column value="{!event.StartDateTime}"/>
</apex:pageBlockTable>
</apex:pageBlock>
I have attached my visualforce page result and salesforce component display today Events.