How to set value in Date and DateTime fields when using ‘defaultFieldValues’ Spring 20 feature?
The Spring ’20 ‘defaultFieldValues’ feature is quite a replacement for the infamous URL hack. But is it as good as the URL hack? Maybe, or maybe not. I will leave that for you to decide.
Too much talk, let’s cut to the chase! So I recently read somewhere that it might not be possible to set the date field values using the ‘defaultFieldValues’ Spring ’20 feature. Now that got me thinking, is it really not possible? Well I tried the normal way and that certainly didn’t work. And sadly there is not much in the documentation for this feature to refer to. But then I came across this.
So this indicates that the input to the ‘defaultFieldValues’ is passed as a string. And that is it! That’s the clue we needed.
So I did what you already might have guessed by now, and i.e. pass the value to the date field as a text value.
So let’s say we want to set a default value of CloseDate field on Opportunity object to current date plus 3 days, using ‘defaultFieldValues’ feature. So the URL for the button would be:
/lightning/o/Opportunity/new?defaultFieldValues=Name=Test Opp,CloseDate=
{!TEXT(TODAY() + 3)}
So all I did was to use TEXT() function to convert the date to a string(text) format and that did the trick! 😎 *dab*
Quick Demo

[Update June 2020]
To set the default value for a date time field, you can use somthing like this: DateTime__c = {!TEXT( DATEVALUE(Object.DateTimeField__c) )}T{!TEXT( TIMEVALUE(Object.DateTimeField__c) )}Z
Hope you find this useful! See you in the next one! ✌
Thank you for being an awesome reader! Subscribe to this blog for receiving all the latest updates straight to your inbox. 🙂

.png)





Comments