+ Start a Discussion
TMangoTMango 

Unexpected Error: ILLEGAL in Javascript with Validated Field Line Breaks

I have a custom button that executes Javascript which validates that each field in the address is completed, and if so, is populating an email with a specific VF template.  We have found that in Accounts where the address contains line breaks ( see below ), the button fails with the dreaded Unexpected Error: ILLEGAL message.  If we fix the address, the button works great.

Just wondering if there is a way to change the button so that it will work by either programmatically removing the line breaks or otherwise allowing the validation?

This Address will not work:
123 Main Street
Building 456
Suite 789

This Address will work:
123 Main Street, Building 456, Suite 789

Current button:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

var criteria1 = "{!Account.BillingStreet}"; 
var criteria2 = "{!Account.BillingCity}"; 
var criteria3 = "{!Account.BillingState}"; 
var criteria4 = "{!Account.BillingPostalCode}";
var criteria5 = "{!Account.BillingCountry}"; 

if ( criteria1 == "" ) {
   alert ("Please ensure that Street, City, State, Postal Code and Country are complete.  This information will be passed to the client contact for validation during the CDD Acknowledgment process.");

} else if ( criteria2 == "" ) {
   alert ("Please ensure that Street, City, State, Postal Code and Country are complete.  This information will be passed to the client contact for validation during the CDD Acknowledgment process.");

} else if ( criteria3 == "" ) {
   alert ("Please ensure that Street, City, State, Postal Code and Country are complete.  This information will be passed to the client contact for validation during the CDD Acknowledgment process.");

} else if ( criteria4 == "" ) {
   alert ("Please ensure that Street, City, State, Postal Code and Country are complete.  This information will be passed to the client contact for validation during the CDD Acknowledgment process.");

} else if ( criteria5 == "" ) {
   alert ("Please ensure that Street, City, State, Postal Code and Country are complete.  This information will be passed to the client contact for validation during the CDD Acknowledgment process.");

} else {

location.replace('_ui/core/email/author/EmailAuthor?p3_lkid={!Account.Id}&retURL=%2F{!Account.Id}&template_id=00X8A000000DboK&new_template=1');

}