You need to sign in to do that
Don't have an account?
Why is this assert failing?
System.Debug('Lead Date is ' + Leads[0].Last_Visit_Date__c); System.Debug('Task Date is ' + Tasks[0].Last_Visit_Date__c ); System.ASSERT(Tasks[0].Last_Visit_Date__c == Leads[0].Last_Visit_Date__c);
In the debug log, I see that the two date/times are equal.
09:14:49.039 (5039665000)|USER_DEBUG|[39]|DEBUG|Lead Date is 2011-06-13 16:14:45
09:14:49.039 (5039832000)|USER_DEBUG|[40]|DEBUG|Task Date is 2011-06-13 16:14:45
09:14:49.040 (5040367000)|EXCEPTION_THROWN|[46]|System.AssertException: Assertion Failed
09:14:49.040 (5040601000)|FATAL_ERROR|System.AssertException: Assertion Failed
I have excluded other code, but this is in test method. I have a trigger on lead which updates the task associated with that lead and sets the last visit date.
In the test method, I set the last visit date on Lead and update the lead. I query the database for all tasks associated with that lead and do the assert
I think here's the answer: http://www.salesforce.com/us/developer/docs/api/Content/primitive_data_types.htm
[...] Regular dateTime fields are full timestamps with a precision of one second. [...]
So, the precision of the dateTime field is one second while the dateTime object has a millisecond.
Maybe truncating the value to one second precision before comparing?
All Answers
That's a weird one. Did you try using the getTime to compare the Long representation of each value?
Good Idea.
The long times are different....I don't know why that would be....
10:52:20.602 (7602915000)|USER_DEBUG|[39]|DEBUG|Lead Date is 2011-06-13 17:52:15 Long time is 1307987535554
10:52:20.603 (7603123000)|USER_DEBUG|[40]|DEBUG|Task Date is 2011-06-13 17:52:15 Long time is 1307987535000
Are you assigning the same value or using Now()? The Now() may be different in one call than another. The difference between both values is less than a second, so it doesn't show in the formatted string. If you need them both to be the same value, the code should update one from the other.
I do assign one value from the other in the trigger, not system.now. It appears that millseconds are dropped when storing or querying from the database. When querying from database, the last 3 digits of getTime always seem to be zero.
See code below.
11:20:23.715 (5715860000)|USER_DEBUG|[48]|DEBUG|Lead Date is 2011-06-13 18:20:18 Long time is 1307989218000
11:20:23.716 (5716235000)|USER_DEBUG|[49]|DEBUG|Task Date is 2011-06-13 18:20:18 Long time is 1307989218000
I think here's the answer: http://www.salesforce.com/us/developer/docs/api/Content/primitive_data_types.htm
[...] Regular dateTime fields are full timestamps with a precision of one second. [...]
So, the precision of the dateTime field is one second while the dateTime object has a millisecond.
Maybe truncating the value to one second precision before comparing?
Yes, seems like precision is second in some places, but milliseconds in other places. System.Now() returns in milliseconds.
SFDC should consider this a bug and make it consistent across.