SOLVED

Use SFDC custom object values in the email as token - Velocity Script Issues

Go to solution
Monica_Koran
Level 3

Use SFDC custom object values in the email as token - Velocity Script Issues

I understand that you need to use velocity scripts to pull in custom object data into emails as tokens, but I think I am missing something.

I have a copy of the token here and then I show what it looks like in the acutal email on the lead record and it reads the script, not the value. Thoughts?

pastedImage_0.png

pastedImage_1.png

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Use SFDC custom object values in the email as token - Velocity Script Issues

and it reads the script, not the value

That's not actually what's happening.

When Velocity can't find an object property, it prints the offending code, rather than throwing a fatal error (in Java, which Velocity uses under the hood, such errors would be fatal, but Velocity is more casual so the program can continue).

You can change this behavior using the silence operator:

$!SomeVariable

will print either the value of $SomeVariable or nothing (if $SomeVariable doesn't exist), rather than printing the code itself.

Now, that explains the direct reason why you see the code. It doesn't explain why the reference can't be found in your case. To inspect the contents of the list, do this:

#if( !$Institution_Event_Registration__cList.isEmpty() )

#foreach( $reg in $Institution_Event_Registration__cList )

[${foreach.index}]<br>

${reg}

#end

#end

And when posting code (which is far better than a screenshot) please highlight it using the syntax highlighter, as I have above, so it's readable.

Also, it seems like you're using the default syntax injected by the Script Editor, which will eventually cause problems. Please read these important posts:

https://blog.teknkl.com/strive-to-avoid-velocity-formal-references/

https://blog.teknkl.com/script-editor-array-get-index/

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Use SFDC custom object values in the email as token - Velocity Script Issues

and it reads the script, not the value

That's not actually what's happening.

When Velocity can't find an object property, it prints the offending code, rather than throwing a fatal error (in Java, which Velocity uses under the hood, such errors would be fatal, but Velocity is more casual so the program can continue).

You can change this behavior using the silence operator:

$!SomeVariable

will print either the value of $SomeVariable or nothing (if $SomeVariable doesn't exist), rather than printing the code itself.

Now, that explains the direct reason why you see the code. It doesn't explain why the reference can't be found in your case. To inspect the contents of the list, do this:

#if( !$Institution_Event_Registration__cList.isEmpty() )

#foreach( $reg in $Institution_Event_Registration__cList )

[${foreach.index}]<br>

${reg}

#end

#end

And when posting code (which is far better than a screenshot) please highlight it using the syntax highlighter, as I have above, so it's readable.

Also, it seems like you're using the default syntax injected by the Script Editor, which will eventually cause problems. Please read these important posts:

https://blog.teknkl.com/strive-to-avoid-velocity-formal-references/

https://blog.teknkl.com/script-editor-array-get-index/