Solved! Go to Solution.
If you can do this, I'd love to know!
Otherwise, I tend to take the time to standardize data using CRM fusion in Salesforce.
I keep getting this error message:
An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!
Invocation of method 'substring' in class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: 1 near
Any thoughts?
Did you check the checkbox on the right side of the velocity script and does the lead have a first name?
Yes, to both. Unfortunately no luck.
Hi Noah,
This is Velocity in a nutshell (and don't get me wrong, I love it, it's just quirky): flexible when you don't need it to be, and strict when you don't expect it!
When Velocity calls deep enough into the outer Java environment, you can get error conditions where you might've thought Velo would let you slide.
A prime example is when you try to take the substring of an existing variable that is empty, with any index other than 0:
#set( $a = "" )
$!{b.substring(0,1)} <-- no error!
$!{a.startsWith("ABCDE")} <-- no error!
$!{a.substring(0,1)} <-- error!
Note how calling substring() on the nonexistent variable $b doesn't cause an error, but the substring on existing-but-empty $a is an error. This is what I mean by the flexible vs. strict dichotomy being kind of surprising.
To avoid this error, wrap in isEmpty():
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end
Also see my comments here, and if you're getting into VTL in Marketo you should read and/or subscribe to my blog, if I do say so. See my VTL posts at http://blog.teknkl.com/tag/velocity.
Oh, and also it's almost always better to open a new thread (you can link back to an old one for reference). Old threads can never be closed by anyone but the OP, and more than one answer can never be marked Correct.
Hi Sanford,
Success! Thanks so much for the help. Brand new to Velocity but your reply explains things very clearly.
I've subscribed to your blog!
Thanks,
Noah
Great x2!
One more quick question about this script.
This appears to add an extra space after the token. For example, the output is "Dear XXX ,"
How can I remove that space in between the end of the name and the comma?