I'm trying to create a fairly simple Email Script Token.
We have a Lookup field from Account to a custom object called District.
On District - we have another Lookupfield to User, and then formula fields to grab the user email and phone number.
So we created Email Script Tokens for those fields and pull them into the email...
When we send the email with the token the token doesn't translate to the value - but continues to display this: Phone: ${District__cList.get(0).CSR_Phone__c}
Any ideas what we could be doing wrong? Thank you!!
When Velocity encounters an unresolved reference (e.g. nonexistent property) that's when you see the barebones VTL code. Your output suggests the list does not exist for the lead you're testing.
Let's debug the object list. Add this to the token:
#if( !$context.contains("District__cList") )
District list does not exist in context.
#else
District list exists.
#set( $listSize = $District__cList.size() )
#if( $listSize == 0 )
List is empty.
#else
List size: $listSize.
List values: ${display.list($District__cList,"<br>")}
#end
#end
Thank you Sanford Whiteman - I added that script as a token and sure enough: District list does not exist in context.
I double checked that the account I am using as the sample has a District linked to it - and that the Marketo Profile in SFDC has read permission to both that lookup field on the account as well as the fields on the District custom object.
Not sure if this is a factor or not - but the relationship is a lookup field from Account to District - so for any one account it would only have one District assigned (as opposed to a list, like a related list) - is that a factor?
Any suggestions on where to from here would be very much appreciated! Thank you!
Removing the .get(0) or checking to ensure there's no duplicate record with a matching email address are two steps maybe to try as well.
FYI, .get(0) on a 0-sized array causes a fatal Java error (index dereference error) not a graceful exit, so it can't be that.
Generally, Velocity gracefully exits on nonexistent objects or properties, but once you get into nonexistent indices, Java handles it and will error out.
I have a strong feeling this "second-level" object connection isn't supported in Velocity. Most aren't -- the only documented exception is Opportunity -- even though you'll still see them, confusingly, in the tree in Script Editor.
Drat. So I suppose next best is to pull the fields from the District object onto the Account as formula fields and use them from there?
Hey Sanford Whiteman I'm running into a similar, but slightly different scenario. I plugged in your debug code above, and received the "Case list does not exist in context" error. However, I'm successfully pulling values from two other fields from the same custom SFDC object. Attached is a screenshot of the relationship in the admin menu for this object.
The debugging code is obsolete because Marketo removed ContextTool in June of this year. Can you open a new thread and describe your situation in more detail?
Sure can. Thanks!