function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael AllenMichael Allen 

Can you spot the JS error?

Hi All,

Bashing my head on a wall with ths one - should be straight forward, but can't see it.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

IF(ISBLANK({!Lead.Parent_Account__c})){
alert ("Opportunity Amount cannot be blank")
}
else{
window.open('/001/e?acc8={!Lead.Annual_Revenue_as_Number__c}&acc2={!Lead.Company}&00N20000001N2Sm={!Lead.Account_Territory__c}&acc7={!Lead.Industry}&acc10={!Lead.Phone}&acc12={!Lead.Website}&acc17street={!Lead.Street}&acc17city={!Lead.City}&acc17state={!Lead.State}&acc17zip={!Lead.PostalCode}&acc17country={!Lead.Country}&00N20000002MmaF={!Lead.NumberOfEmployees}&00N20000003SB9T={!Lead.Users_with_Admin_Rights__c}& 00N20000002t8Zx={!Lead.End_Point_Protection__c}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Mac OS") , "Mac OS" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Server 2003") , "Server 2003" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Server 2008") , "Server 2008" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Vista") , "Vista" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 2000") , "Windows 2000" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 7") , "Windows 7" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 8") , "Windows 8" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 8.1") , "Windows 8.1" , "")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"XP") , "XP" , "")}&00N20000001z52Q={!Lead.Number_of_Desktops__c}&00N20000001z52V={!Lead.Number_of_Laptops__c}&00N20000003S1MU={!Lead.Macs__c}&00N20000002MauY={!Lead.Number_of_Servers__c}&00N20000009XcUR={!Lead.Id}&retURL=/{!Lead.Id}');
}
In short, I've got a detail page button on Lead that will create an Account thru the URL. Once I realised I needed valudation on it to prevent Accounts being created from Leads that were already associated to Accounts, I changed the button execute Javascript and added the IF statement above.
Problem is, I get this error:
missing ) after argument list
BUT.... if I reference a standard field in the statement (say, {!Lead.Phone}) I get
missing ; after argument list

I'm relatively new to the dev side of SF, and am stumped by this. Can anybody shed any light?

Appreciated as always.
Michael
Swati GSwati G
Are you getting this error while saving button code?
Michael AllenMichael Allen
No, save is successful. It happens when executing by clicking the button.
Swati GSwati G
You should use URLENCODE in parameter, as in url some field might be having single quote or some special character.
BugudeBugude
I agree, URLENCODE takes case of the escape characters.

if you dont want to encode it then check for spaces or any unsafe characters in URL.
In this, I see a space "& 00N20000002t8Zx". Please remove the space and check if this resolves the issue.
Michael AllenMichael Allen
Thanks Guys

I've removed all of those spaces (hang over from when I was just copiling a URL to run in a new window), which has resolved the ) and ; errors. But I'm now getting
Unexpected token {

Here is my updated code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
IF(ISBLANK({!Lead.Parent_Account__c})){
alert("Opportunity Amount cannot be blank");
}
else{
window.open('/001/e?acc8={!Lead.Annual_Revenue_as_Number__c}&acc2={!Lead.Company}&00N20000001N2Sm={!Lead.Account_Territory__c}&acc7={!Lead.Industry}&acc10={!Lead.Phone}&acc12={!Lead.Website}&acc17street={!Lead.Street}&acc17city={!Lead.City}&acc17state={!Lead.State}&acc17zip={!Lead.PostalCode}&acc17country={!Lead.Country}&00N20000002MmaF={!Lead.NumberOfEmployees}&00N20000003SB9T={!Lead.Users_with_Admin_Rights__c}&00N20000002t8Zx={!Lead.End_Point_Protection__c}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Mac OS"),"Mac OS","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Server 2003"),"Server 2003","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Server 2008"),"Server 2008","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Vista"),"Vista","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 2000"),"Windows 2000","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 7"),"Windows 7","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 8"),"Windows 8","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"Windows 8.1"),"Windows 8.1","")}&00N20000001z52W={!IF(INCLUDES(Lead.Operating_System__c,"XP"),"XP","")}&00N20000001z52Q={!Lead.Number_of_Desktops__c}&00N20000001z52V={!Lead.Number_of_Laptops__c}& 00N20000003S1MU={!Lead.Macs__c}&00N20000002MauY={!Lead.Number_of_Servers__c}&00N20000009XcUR={!Lead.Id}&retURL=/{!Lead.Id}');
}

Can anybody see anything jumping out at you?
Michael AllenMichael Allen
Also, I have eliminated the URL as the source of the error. I replaced it with simply
window.open('/001/e');
}

which should just open a new record, but it's still throwing the same Unexpected token { error. :-(