When you have automated processes interacting with your system, it is very common for multiple things to happen within the same second. In order to prove that these events happened in the correct order, it would be nice to have millisecond precision time-stamps on these records. Unfortunately, datetime fields seem to only store datetimes with second precision.

Is there a way to activate millisecond precision for datetime fields, or when needed do people resort to using a work-around?

My initial impulse is to use System.now().getTime() to get a time-stamp with millisecond precision, and store it in a number field.


Yes, unfortunately second precision is as close as you can get, especially for audit fields (created date, last modified date). Using getTime will allow you to get closer to millisecond precision, so you may want to use that method when you need the extra precision. Strictly speaking, though, you can't control the order of things like triggers, so there might still be some discrepancy if you deploy extra triggers on an object (so, use one trigger per object if you want predictability).

|improve this answer|||||
  • In my particular case, we have an external system that will first push data into multiple salesforce objects using multiple requests and then flag the parent record to pass the data on to another system. Just for the sake of trouble-shooting, I wanted to be able to prove that the data wasn't getting passed out of salesforce before all of the data got moved in. – martin May 18 '17 at 3:41
  • It's too bad the standard audit fields won't work for this. – martin May 18 '17 at 3:41
  • @martin Yeah, until/unless they implement millisecond audit fields, we're stuck with doing things manually. – sfdcfox May 18 '17 at 3:43

I generally store both. The date is there for quick visual analysis and a UTC milliseconds since epoch field.

The reason I would do that is most database implementation may store the date without timezone information or use the local date time causing issues during daylight savings time.

As such I would do any time based calculations on that field.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.