Ugh. I know I've asked very similar things to this before, so I feel like I should know better....but I'm having trouble comparing a date to today's date. I've successfully done this in the past with two points in time, but not when one is today's date....and that's tripping me up. Here's what I have so far. $LTD.Expiry_Date__c is a date field that comes in from Salesforce like this: "2015-11-05".
##set time zone and locale settings for date conversions #set( $TimeZone = $date.getTimeZone().getTimeZone('America/New York') ) #set( $locale = $date.getLocale() ) ##set a calendar object #set( $calNow = $date.getCalendar() ) #set( $calConst = $field.in($calNow) ) #set ($validCredits = ) #if( ! $LTD.Expiry_Date__c) #set ($discard = $validCredits.add($LTD.Compass_ID__c)) #else ##set travel credit expiry date and convert it to a date, then a calendar so we can compare later #set($TravelCreditExpiryDate = $LTD.Expiry_Date__c) #set($TravelCreditExpiryDate = $convert.parseDate($TravelCreditExpiryDate,'yyyy-MM-dd',$locale,$TimeZone)) #set($TravelCreditExpiryDate= $date.toCalendar($TravelCreditExpiryDate)) ##compare the expiry date of the travel credit to today's date. ##if expiry date is in the future, add to valid credits list. #if ( $calNow.compareTo($TravelCreditExpiryDate) < 0) #set ($discard = $validCredits.add($LTD.Compass_ID__c)) #end #end
Here is the error I get:
Cannot get email content- <div>An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?! </div> <p>Invocation of method 'compareTo' in class java.util.GregorianCalendar threw exception java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Calendar near</p> <div><pre >?</pre></div>
So either my travel credit isn't being formatted properly, or my current date $calNow isn't. I think the travel credit part is right since I've used that before. So I'm guessing it's today's date. But how can I fix this?
Thanks in advance.