SOLVED

Email bounce error: Velocity transform failed

Go to solution
Brittany_La
Level 2

Email bounce error: Velocity transform failed

Hi there,

I've had an email campaign set up with a few Velocity-scripted tokens for a while, and have recently been getting this error on email bounces:

Velocity transform failed: ;The nested exception is:<cntrl char>org.apache.velocity.exception.MethodInvocationException: Invocation of method 'compareTo' in  class java.lang.String threw exception java.lang.NullPointerException at 290-ZGA-843:19890:1:static[line 22, column 75]

I've no idea where to even begin troubleshooting this. Any thoughts on where to begin?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email bounce error: Velocity transform failed

The NPE is (as the error says) because you can't pass null to compareTo.  And $opportunity.Pipeline_Notification_Date__c can be null.

While you may not have been expecting null there, why are you using .compareTo(other) == 0 instead of .equals(other)?  The former will throw on null, while the latter is a valid method call (it will return false if the argument is null).

And for your purposes, if you want to check equality between 2 native Strings, there's no reason not to use .equals()

You only need to use .compareTo() if your objects don't have specialized .equals() logic coded in -- or you don't like either side's .equals() method for some reason -- but the objects do have specialized sorting logic you want to reuse. (In Java-speak, an object that has different rules for sorting and for equality is said to have "ordering inconsistent with equals" and you want to avoid this whenever possible anyway.)

P.S. Looks like you're also mixing up the timezone-d dates and the built-in $date in various places, which means your comparisons can be off (remember that dates that are parsed in different timezones will be different dates for between 1 and 23 hours).

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Email bounce error: Velocity transform failed

Please post the Velocity code itself, highlighting it as Java using the Advanced Editor's syntax highlighter.

And  provide notes about the fields in use if not self-explanatory.

Brittany_La
Level 2

Re: Email bounce error: Velocity transform failed

Hi Sanford,

Thanks for your reply. See below for the codes. I am using them to create various tokens to insert into an email template.

Token 1

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set($today = $date.format('yyyy-MMM-dd',$date))
$calNow.add($calConst.DATE,45)
#set($today = "MMM dd, yyyy")
${date.format(
$today,
$calNow
)}

Token 2

#set($today = $date.format('yyyy-MM-dd',$date))
#foreach($opportunity in $OpportunityList)
#if($opportunity.Pipeline_Notification_Status__c.contains("45") && $today.compareTo($opportunity.Pipeline_Notification_Date__c)==0)
#set ($matchedOppt = $opportunity)
#break
#end
#end
#if($matchedOppt)
$number.currency($matchedOppt.Amount)
#else
your amount
#end

Token 3

#set($today = $date.format('yyyy-MM-dd',$date))
#foreach($opportunity in $OpportunityList)
#if($opportunity.Pipeline_Notification_Status__c.contains("45") && $today.compareTo($opportunity.Pipeline_Notification_Date__c)==0)
#set ($matchedOppt = $opportunity)
#break
#end
#end
#if($matchedOppt)
$matchedOppt.LH_Loan_Id__c
#else
null
#end

Token 4

#set($today = $date.format('yyyy-MM-dd',$date))
#foreach($opportunity in $OpportunityList)
#if($opportunity.Pipeline_Notification_Status__c.contains("45") && $today.compareTo($opportunity.Pipeline_Notification_Date__c)==0)
#set ($matchedOppt = $opportunity)
#break
#end
#end
#if($matchedOppt)
$matchedOppt.LH_Loan_Id__c
#else
null
#end

Token 5

#set($today = $date.format('yyyy-MM-dd',$date))
#foreach($opportunity in $OpportunityList)
#if($opportunity.Pipeline_Notification_Status__c.contains("45") && $today.compareTo($opportunity.Pipeline_Notification_Date__c)==0)
#set ($matchedOppt = $opportunity)
#break
#end
#end
#if($matchedOppt)
$matchedOppt.Property_Address__c
#else
your address
#end
SanfordWhiteman
Level 10 - Community Moderator

Re: Email bounce error: Velocity transform failed

The NPE is (as the error says) because you can't pass null to compareTo.  And $opportunity.Pipeline_Notification_Date__c can be null.

While you may not have been expecting null there, why are you using .compareTo(other) == 0 instead of .equals(other)?  The former will throw on null, while the latter is a valid method call (it will return false if the argument is null).

And for your purposes, if you want to check equality between 2 native Strings, there's no reason not to use .equals()

You only need to use .compareTo() if your objects don't have specialized .equals() logic coded in -- or you don't like either side's .equals() method for some reason -- but the objects do have specialized sorting logic you want to reuse. (In Java-speak, an object that has different rules for sorting and for equality is said to have "ordering inconsistent with equals" and you want to avoid this whenever possible anyway.)

P.S. Looks like you're also mixing up the timezone-d dates and the built-in $date in various places, which means your comparisons can be off (remember that dates that are parsed in different timezones will be different dates for between 1 and 23 hours).

Brittany_La
Level 2

Re: Email bounce error: Velocity transform failed

That all makes sense. Admittedly I was using .compareTo() because I wasn't aware of .equals() but your explanation makes sense and I will adjust my tokens.

Do you mean that I should be specifying the timezone in each token where I call $date ?

SanfordWhiteman
Level 10 - Community Moderator

Re: Email bounce error: Velocity transform failed

Do you mean that I should be specifying the timezone in each token where I call $date ?

Yes, wherever you simply serialize $date to a string, it's using the system timezone (US CST) so that won't necessarily match the intended timezone of your other dates.

Brittany_La
Level 2

Re: Email bounce error: Velocity transform failed

That makes sense. Thank you for clarifying!