Soft bounced due to Velocity transform failed error.

Anonymous
Not applicable

Soft bounced due to Velocity transform failed error.

Hello,

I'm getting soft bounce issue while using below velocity script, when I checked in the Activity log found following highlighted error. Could any one help me to understand the root cause in the scripting since i'm unable to find it.

Velocity transform failed: ; The nested exception is: <cntrl char>org.apache.velocity.exception.VelocityException: Error invoking method 'get(java.lang.Integer)' in [Ljava.lang.String; at 917-ATW-131:55806:1:static[line 218, column 33]

#set($courseId = "")

#set($timeZone = "")

#set($courseDate = "")

#set($courseName = "")

#set($courseLessonName = "")

#set($courseLessonTime1 = "")

#set($courseLessonTime2 = "")

#set($courseLessonTimeZone1 = "")

#set($courseLessonTimeZone2 = "")

#set($attendancerating = "")

#set($campaignid = "")

#set($webinar_URL0 = "www.ABC.com/login.php")

#set($webinar_URL1 = "")

#set($attendancerating = ${lead.sfLeadAttendanceRating})

#set($WebinarData = ${lead.phoenixWebinarURLs})

#set($WebinarData = $WebinarData.replace("&amp;","&"))

#foreach($data in $WebinarData.split(";"))

#if($data == "")

#set($webinar_URL1 = $webinar_URL0)

#elseif(!$data.equals(""))

#set($templateData = $data.split("\|\|"))

#set($courseId = $templateData[0])

#set($courseDate = $templateData[1])

#set($timeZone = $templateData[2])

#set($courseName = $templateData[3])

#set($courseLessonName = $templateData[4])

#set($courseWebinarURL = $templateData[5])

#set($courseLessonTime1 = $templateData[6])

#set($courseLessonTimeZone1 = $templateData[7])

#set($courseLessonTime2 = $templateData[8])

#set($courseLessonTimeZone2 = $templateData[9])

#set($courseQuiz = $templateData[10])

#set($campaignid = $templateData[11].replace("_",""))

#break

#end

#end

#set($courseQuizpart= $courseQuiz)

#if($lead.phoenixWebinarURLs.equals(""))

<a style="color: #ffffff; text-decoration: none;" href="https://${webinar_URL1}?leadId=${lead.mongoLeadId}&email=${lead.Email}&zone=${lead.Webinar_Timezone__c}&campaign_id=${campaignid}"><span style="text-decoration: none; color: #ffffff;">TEST YOUR KNOWLEDGE</span></a>

#elseif($courseQuiz == "")

<a style="color: #ffffff; text-decoration: none;" href="https://${webinar_URL1}?leadId=${lead.mongoLeadId}&email=${lead.Email}&zone=${lead.Webinar_Timezone__c}&campaign_id=${campaignid}"><span style="text-decoration: none; color: #ffffff;">TEST YOUR KNOWLEDGE</span></a>

#else

<a style="color: #ffffff; text-decoration: none;" href="https://${courseQuizpart}?leadId=${lead.mongoLeadId}&email=${lead.Email}&zone=${lead.Webinar_Timezone__c}&campaign_id=${campaignid}"><span style="text-decoration: none; color: #ffffff;">TEST YOUR KNOWLEDGE</span></a>

#end

Thanks,

Priyesh

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Soft bounced due to Velocity transform failed error.

Please, please use syntax highlighting when posting code. Screenshot of the the Advanced Editor:

pastedImage_0.png

An error invoking get() occurs when you try to access an integer array index that doesn't exist.

There are also some things in the code I would definitely clean up as it's far too long for the task. For one, this condition doesn't make sense:

#if( $data == "" )

#elseif(!$data.equals(""))

#end

Since $data can't be null as it comes from a call to split(), looks like you can just use:

#if( $data.isEmpty() )

#else

#end

Also, if you're trying to do a sort of "destructuring assignment" from an array, set up a template and use object properties for cleaner code:

#set( $courseTemplate = "courseId||courseDate||timeZone||courseName" )

#set( $courseFields = $courseTemplate.split("\|\|") )

#set( $courseValues = $data.split("\|\|") )

#set( $course = {} )

#foreach( $value in $courseValues )

#set( $course[$courseFields[$math.sub($velocityCount,1)]] = $value )

#end

This method lets you instantly reorder or remove elements from the expected data.

I recommend you refactor the code. This will help you isolate where the bad index is being accessed.