Thursday, July 23, 2009

Salesforce APEX "Invalid bind expression type of Datetime for column of type Date"

When trying to compare a Date field with a DateTime field in an APEX SOQL query I got the following error:

Invalid bind expression type of Datetime for column of type Date

The solution was to use date.newinstance(year, month, day) rather than the raw DateTime value in the comparison. Year, month, and day are found using the methods of the same name on the DateTime object.