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

SOQL Error



In my batch apex class I have query variable. this query is dynamic based on the passed values from the controller. I am getting the datetime value from the controller and initializing that value to a dateTime variable in the BatchApex constructor and trying to compare that datetime value  in the query.


I am perfectly fetching the datetime value and I can see the value in the BatchApex class also. But the problem is in the quey  it is returning null(comparing with createddate> datetime value provided) resulting invalid operator in the start() method.  Apprecialte help.


Here is my sample code:




    global final ID CampaignId;
    global  dateTime DT;


    public String query =
        ' select  Call_Outcome__c,Comments__c ' + 
        '  from testtable__c '+
        ' where createdDate > '+DT+'' +
        ' and Iscon__c = False '+
        '   and Isgov__c = True ';

    //constructor - initializing CampaignId from the controller
    global BatchTest (ID CampId, dateTime givenDateTime)
        DT= givenDateTime;


I wonder if you are hitting a timezone issue.


We've found that the datetime is stored against the object as a GMT time, so we have to convert the datetime that the user inputs into GMT in order to carry out a meaningful comparison.


For example, we have some code that retrieves all items for the current day.  We are in the UK, so during the summer our timezone is GMT+1.  If we just used the date/time that the user input, we got events from 23:00 the previous day through to 23:00 on the current day.