-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 2, 2018 5:42 PM (in response to Phillip Wild)It's not $calNow that's the problem, because if it were null or another non-Calendar value it wouldn't have a compareTo method at all.
The prob is certainly with your custom field remaining a String because it can't be converted. You have a condition in there that suggests it may be empty. In that empty case the Calendar conversion will fail, and in turn the compareTo will error out, but you haven't short-circuited the rest of the processing.
-
Re: Velocity - comparing to today's date
Phillip Wild Dec 2, 2018 3:54 PM (in response to Sanford Whiteman)Hmm....I still don't think I get it. Since my code structure is basically this (after changing to isEmpty for logic):
#if( $LTD.Expiry_Date__c.isEmpty())
#set ($discard = $validCredits.add($LTD.Compass_ID__c))
#else
##compare dates
#end
So if my first check is to see whether it's empty.....then the #else section should only be dealing with circumstances where there is a value in there, right? Since the field is a date field in Salesforce I know the output must be either empty, or yyyy-mm-dd. So why would my #else section be failing if it's only applying where the value is there?
To test this further I got the output of that field for the test lead where this is failing (using preview of the email and selecting sample lead). The field value is:
Expiry_Date__c=2015-12-15
What am I missing here.....
-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 2, 2018 6:53 PM (in response to Phillip Wild)1 of 1 people found this helpfulIt's
America/New_York
not
America/New York
(Was on my phone before so I didn't notice this typo.)
Because of the typo, $TimeZone is never set. Thus the later use of $TimeZone in the conversion to Date fails silently, and the variable remains as-is, a String.
-
Re: Velocity - comparing to today's date
Phillip Wild Dec 4, 2018 2:50 PM (in response to Sanford Whiteman)Ah, of course! Duh.
Now that is solved, I went back and modified my simple "checks based on having a value" (eg. $LTD.Amount__c) to be checking on isEmpty (eg. $LTD.Amount__c.isEmpty() ).
But here's the weird thing. Those logic checks don't seem to be working for some reason using the Preview. Here's what works:
#elseif($LTD.Type__c == "Travel Credit" && ! $LTD.Applied_To__c && $LTD.Amount__c)
And what doesn't:
#elseif($LTD.Type__c == "Travel Credit" && $LTD.Applied_To__c.isEmpty() && ! $LTD.Amount__c.isEmpty() )
I know you said above that using isEmpty is more reliable. But that's not what I'm finding in this example. Why so?
(When I output the fields of "Applied_To" and "Amount__c" for this lead it displays as "Applied_To__c=null". So the value is definitely null in there.
-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 4, 2018 3:10 PM (in response to Phillip Wild)1 of 1 people found this helpfulIt's not that one is more reliable than the other, it's that they do totally different things.
$var.isEmpty() checks if a reference is an empty String.
!$var checks if a reference is Boolean false or null or does not exist in the Velocity context.
If you come from a background in popular dynamic languages, you might assume that !$var is false for empty Strings. Velocity sometimes is dynamically typed (or more like error-suppressing) and sometimes is strongly typed.
-
Re: Velocity - comparing to today's date
Phillip Wild Dec 10, 2018 7:42 AM (in response to Sanford Whiteman)Thanks Sanford! Can you tell I never went to programming school?
-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 10, 2018 11:03 AM (in response to Phillip Wild)Me neither, technically! But I'm founding the School of Velocity. You're gonna like the next blog post, I think.
-
-
-
-
-
-
-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 2, 2018 5:42 PM (in response to Phillip Wild)1 of 1 people found this helpfulAlso, you're testing for Boolean false, not empty. You should be using isEmpty there.
-
Re: Velocity - comparing to today's date
Sanford Whiteman Dec 8, 2018 5:06 PM (in response to Phillip Wild)Phillip please come back to the thread and mark one of my answers as Correct (probably the one noting the typo) for future searches, thanks.