You need to sign in to do that
Don't have an account?

Illegal token on button action
Hello -
I'm trying to switch this URL action on the button to a javascript action. Before, whatever was in window.open (see below) was alone and it was set to the URL behavior.
I'm still getting an illegal token error. I don't see what is going wrong.
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}
var leadAddress = '{!Lead.Address}';
var leadCity = '{!Lead.City}';
var leadState = '{!Lead.State}';
var leadCountry = '{!Lead.Country}';
if(leadAddress == null || leadAddress == ''){
alert('Please enter Address before clicking on this button');
}
else if(leadCity == null || leadCity == ''){
alert('Please enter City before clicking on this button');
}
else if(leadState == null || leadState == ''){
alert('Please enter State before clicking on this button');
}
else if(leadCountry == null || leadCountry == ''){
alert('Please enter Country before clicking on this button');
}
else{
window.open('
/a0J/e?
CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }
&CF00Nj00000091TUH_lkid={!Lead.Id}
&retURL=%2F{!Lead.Id}
&saveURL=%2F{!Lead.Id}
&RecordType=012j0000000pfbL
&ent=01Ij0000001EVex
&00Nj00000091TU6={!Lead.Company}
&00Nj00000091TUQ=Pending');
}
I'm trying to switch this URL action on the button to a javascript action. Before, whatever was in window.open (see below) was alone and it was set to the URL behavior.
I'm still getting an illegal token error. I don't see what is going wrong.
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}
var leadAddress = '{!Lead.Address}';
var leadCity = '{!Lead.City}';
var leadState = '{!Lead.State}';
var leadCountry = '{!Lead.Country}';
if(leadAddress == null || leadAddress == ''){
alert('Please enter Address before clicking on this button');
}
else if(leadCity == null || leadCity == ''){
alert('Please enter City before clicking on this button');
}
else if(leadState == null || leadState == ''){
alert('Please enter State before clicking on this button');
}
else if(leadCountry == null || leadCountry == ''){
alert('Please enter Country before clicking on this button');
}
else{
window.open('
/a0J/e?
CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }
&CF00Nj00000091TUH_lkid={!Lead.Id}
&retURL=%2F{!Lead.Id}
&saveURL=%2F{!Lead.Id}
&RecordType=012j0000000pfbL
&ent=01Ij0000001EVex
&00Nj00000091TU6={!Lead.Company}
&00Nj00000091TUQ=Pending');
}
All Answers
The issue is you have line breaks in your window.open string, which JavaScript does not like. Instead, it's expecting to find a closing single quote. Replace the window.open call with the following, and you'll fix your ILLEGAL TOKEN error:
Also, when you post code on these forums (JS, Apex, Visualforce, whichever), please use the code format (< >) button. This will help us easily read your code and copy and paste if need be. Thanks!