Pages

Monday, November 20, 2017

Salesforce: Time field (Beta)

This blog is written with Winter '18 release, where time field still in Beta, let us expect many improvements in Spring '18 release. This feature is enabled by default in Sandbox, but you need to request Salesforce if you would like to enable it for production.

This function has been requested in Idea Exchange since 10 years ago, and at this moment it has 5,530 points.

There are 2 types of Time fields in Winter '18 beta:
- as a custom field with Data Type = Time, or
- as a Formula field that returns type = Time

1. Custom field with Data Type = Time
As of now still in Beta, the display in Lightning is not great, but display in Classic is much nicer.


As this is not formula field, users with appropriate permission able to type in the time directly into the page layout.

For this blog, I'll use Classic for testing.
You can enter the time in 24 hours format:
- "18", when you save, this will save as 6:00 PM
- "18:12", when you save, this will save as 6:12 PM
- "7:12", when you save, this will save as 7:12 AM
- "7.32", when you save, this will save as 7:00 AM  --> 18.12 (dot) will be ignored

You also can enter the time in 12 hours format with AM/PM:
- "12 AM", when you save, this will save as 12:00 AM
- "12:30PM", when you save, this will save as 12:30 PM


2. Formula Field return Time
Sample: MINUTE(Approved_Time__c), HOUR(Approved_Time__c)
To calculate hours and minutes between time fields, you cannot just minus or add them directly, Submission_Time__c - Approved_Time__c will return error "Incorrect parameter type for operator '-'".

To display the difference between 2 times, you can use formula field to return the formula as text, example:
IF( (MINUTE(Approved_Time__c) - MINUTE(Submission_Time__c)) >=0,
TEXT((HOUR(Approved_Time__c) - HOUR(Submission_Time__c)))
& ":" &
TEXT((MINUTE(Approved_Time__c) - MINUTE(Submission_Time__c))),
TEXT((HOUR(Approved_Time__c) - HOUR(Submission_Time__c) - 1))
& ":" &
TEXT((MINUTE(Approved_Time__c) - MINUTE(Submission_Time__c) + 60))
)

To read the complete documentation, read this article, and if you have further questions, feel free to join Custom Time Field success community.


Reference: