Advanced My Tokens: Apache Velocity and Null checking | Community
Skip to main content
October 28, 2014
Question

Advanced My Tokens: Apache Velocity and Null checking

  • October 28, 2014
  • 2 replies
  • 1400 views
Hey guys, i'm getting started with Velocity and am trying to check if a record in Salesforce's Name is blank, and do some logic.

I've solved this by switching the null check to $foo != "" but I'm still interested to see what you guys know about Nulls in Marketo's implementation of Velocitybecause the information I've seen online is sporadic, I'm going to encounter it later, and the stuff I've played with below threw a minimalistic error:
 
#set( $foo = ${lead.FirstName} )

#if ($foo != null)
  Hello $foo!
#else
  Hello Unknown Person!
#end

When sending test email:
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

October 28, 2014
I am guessing you are seeing this error because FirstName does not return anything if there is no value.

Here's how I would implement this. Let me know what you think? 

#set( $foo = ${lead.FirstName} )
#set( $blank = "" )

#if ($foo == $blank)
  Hello Unknown Person!
#else
  Hello $foo
#end
October 29, 2014
I was more after how (and if) nulls are handled in Velocity/Marketo. In the last 10 minutes I think I've read that null isn't supported in Velocity, but if you import a bunch of Java that isn't used by Velocity you can enable them.

Maybe I'm not thinking about it right: Do nulls get pulled from SFDC or does it only ever get empty strings?