[SalesForce] SOQL DateTime Greater than Date

For the life of me I cannot figure out how to query tasks greater than a given DateTime. I have a field, inqDateTime, that I need to pull tasks greater than that date. I have tried to convert the DateTime to a Date field, but then I get zero returns because it lacks the T and Z from the value, I guess?

So then I tried to use the DAY_ONLY bit in the WHERE clause, but I get errors like crazy expecting a ; .

How do I use a DateTime field and get all tasks from that date?


For reference, here is my code:

@AuraEnabled
public static integer taskQuery(DateTime inqDateTime, id leadID){
    System.debug('militaryQuarantineController.taskCount running.............................................................');

    //Date inqDate = Date.newInstance(inqDateTime.year(), inqDateTime.month(), inqDateTime.day());
    DATE inqDate = inqDateTime.DATE();
    //String inqDate = DateTime
    System.debug('inqDate = ' +inqDate);
    List<Task> taskList = [SELECT id FROM Task WHERE whoid= :leadID AND TaskSubtype!='Task' AND ActivityDate >= : inqDate];
    System.debug('There are ' +taskList.size()+ ' tasks since the last inquiry');

    integer taskCount = taskList.size();

    return taskCount;
}

Best Answer

It seems the problem was elsewhere in my query. I was not passing the leadID correctly after a couple of other edits. Check all your filters, kids.

For future reference, this will work:

DATE inqDate = inqDateTime.DATE();
List<Task> taskList = [SELECT id FROM Task WHERE whoid= :leadID AND TaskSubtype!='Task' AND ActivityDate >= : inqDate];
Related Topic