Per this answer, and everything I know about Salesforce formulas, if I want the default value of a datetime field to be the current time, I should be able to use the formula now(). In this case, the field is on a Hierarchal Custom Setting, but the principle is the same. The formula editor will accept the formula, but when I go to the Manage page and click "New" to create the org-wide custom setting, I get an error:

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Last Run Time: value not of required type: Fri Aug 31 16:18:48 GMT 2018".

So even though now() returns a Datetime, it's getting treated like a string. I also tried changing the formula to DateTimeValue(now()), but get the same result. Is this a bug or am I overlooking something?

Edit: to clarify, I have a Hierarchy-type custom setting, with a field named Last_Run_Time__c of type DateTime. I wish to enforce a default value of the current time. I set the default value formula to now(), and the system accepted that value. When I try to create the org-wide instance of the custom setting (Custom Setting -> Manage -> New), I get the validation error quoted above. Why does using now() to set the default value of this field result in this error? now() is documented to return a Datetime, not a string.

  • 1
    Its worth raising with SF, This works fine with Sobject and Custom Metadata Types. I cant figure out a reason why this would be different for custom setting. – Pranay Jaiswal Aug 31 '18 at 17:29

Your Answer

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

Browse other questions tagged or ask your own question.