Hi i want to get the all the events in between startdatetime to enddatetime.but i am not getting the records.

My code is:

    public static string eventdata(Datetime starts,Datetime ends){
 for(Event evnt: [select Id, Subject, isAllDayEvent, StartDateTime, EndDateTime from Event where  ownerid=:userinfo.getUserId() and startdatetime>=:starts and enddatetime<=:ends]){

in the vfpage:function getEventData() {

        // records are retrieved from soql database
            // controller and method names
            function(result, event)
                if (event.status) 

In the select query i am not getting values.

The values of starts is 2016-04-22 00:00:00 ends is 2016-04-30 00:00:00 I tried in the query editor if the starts and ends value format like 2016-04-22T00:00:00Z then i am getting the values but in the coding i give starts and ends values like above format i am getting Invalid date/time: 2016-04-21T20:00:00Z

  • Any luck resolving this issue?
    – Adrian Larson
    Apr 25, 2016 at 19:19

1 Answer 1


You are trying to pass String variables for Datetime parameters. Change your method to accept String parameters instead. In order to be able to use Datetime.valueOf, you will need to use a format like 2016-04-22 00:00:00 instead. You will then need to perform the conversion to Datetime yourself:

public static void myMethod(String startTime, String endTime)
    Datetime startDt = Datetime.valueOfGmt(startTime);
    Datetime.endDt = Datetime.valueOfGmt(endTime);
    // other logic

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .