1

When a record is created and trigger executes (after insert)- updating a field, I want to calculate the time difference between the last modified date and the created date in seconds. If it's greater than 10 seconds update the field as true else false. Can someone tell how to calculate in seconds?

1
createdDate-LastModifiedDate

Returns the difference in the number of days - it's like yesterday- today - 1

If you multiply by 24 (24 hours a day ) returns the value in hours

then by 60 (60 minutes) returns the value in minutes

then again another 60 (60 seconds) returns the value in seconds

Difference in seconds

(createdDate-lastModifiedDate)*24*60*60
1

This sounds like a problem I was having - creating a formula checkbox to determine if a record had been updated or not, labeled "IsUpdated". Originally tried just the simple formula:

CreatedDate <> LastModifiedDate

But that always came back TRUE - assuming due to milliseconds difference.

Solution I found to work instead was individually comparing each piece of the DateTime fields, first matching the dates, then breaking the timestamp into Hours and Minutes for comparison.

NOT(
 DATEVALUE(LastModifiedDate) = DATEVALUE(CreatedDate) &&
 HOUR(   TIMEVALUE(LastModifiedDate)) = HOUR(   TIMEVALUE(CreatedDate)) &&
 MINUTE( TIMEVALUE(LastModifiedDate)) = MINUTE( TIMEVALUE(CreatedDate)) 
)
1
  • Thanks for the alternate solution. Will check the HOUR and MINUTE
    – SFDC
    Oct 30 '20 at 6:17

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.