当LastModifiedDate与两个日期进行比较时,Salesforce SOQL查询不返回行

时间:2012-02-09 07:21:38

标签: date salesforce between soql

感谢您花时间看我的帖子。

我正在尝试检索在两个日期之间修改的联系人列表(LastModifiedDate> = Date1 AND LastModifiedDate< = Date2)。当我查询我收到0行。如果我只取出第二部分(LastModifiedDate< = Date2),我会收到很多。

这是我的代码和调试日志 - 首先是两个日期:

DateTime myDate = DateTime.parse('10/05/2011 00:00 AM');
DateTime myLastDate = DateTime.valueOf('2012-02-7 05:04:25');
System.debug('the first date:' + String.valueOf(myDate) + ' and the last date: ' + String.valueOf(myLastDate));
List<Contact> cList = [select id, FirstName, LastName, LastModifiedDate  FROM Contact WHERE Email <> '' AND Email <> null AND LastModifiedDate >= :myDate and lastModifiedDate <= :myLastDate];
system.debug('num cons' + cList.size());

debug

19:19:14.042 (42468000)|USER_DEBUG|[3]|DEBUG|the first date:2011-10-05 00:00:00 and the last date: 2012-02-07 05:04:25
19:19:14.042 (42478000)|SYSTEM_METHOD_EXIT|[3]|System.debug(ANY)
19:19:14.042 (42682000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select id, FirstName, LastName, LastModifiedDate FROM Contact  WHERE  Email <> '' AND Email <> null  AND LastModifiedDate >= :myDate and lastModifiedDate <= :myLastDate
19:19:18.055 (4055043000)|SOQL_EXECUTE_END|[4]|Rows:0

现在有一个日期

DateTime myDate = DateTime.parse('10/05/2011 00:00 AM');
DateTime myLastDate = DateTime.valueOf('2012-02-7 05:04:25');
System.debug('the first date:' + String.valueOf(myDate) + ' and the last date: ' + String.valueOf(myLastDate));
List<Contact> cList = [select id, FirstName, LastName, LastModifiedDate  FROM Contact WHERE  Email <> '' AND Email <> null   AND LastModifiedDate >= :myDate ];
system.debug('num cons' + cList.size());

调试:

19:20:55.039 (39038000)|USER_DEBUG|[3]|DEBUG|the first date:2011-10-05 00:00:00 and the last date: 2012-02-07 05:04:25
19:20:55.039 (39045000)|SYSTEM_METHOD_EXIT|[3]|System.debug(ANY)
19:20:55.039 (39249000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select id, FirstName, LastName, LastModifiedDate FROM Contact   WHERE  Email <> '' AND Email <> null  AND LastModifiedDate >= :myDate
19:21:06.555 (11555339000)|SOQL_EXECUTE_END|[4]|Rows:21784

欢迎任何建议。

1 个答案:

答案 0 :(得分:0)

它刚刚开始工作而我没有任何改变。

感谢大家的帮助。