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

OnClick Javascript error "Unexpected token ILLEGAL



I have a button on a Case page layout. In the JavaScript I am inserting a merge field {!Case.Id}. But when clicking the button I am receiving the error "Unexpected token ILLEGAL". If I try to merge any other field such as {!Case.CaseNumber} it works. Why is there a problem with the Id. I need to pass the Id to an APEX class. I removed all code exept this one line and it fails.


{!REQUIRESCRIPT ("/soap/ajax/15.0/connection.js")} 

{!REQUIRESCRIPT ("/soap/ajax/15.0/apex.js")}


var caseId = {!Case.Id} 


var caseId = {!CaseNumber} works, although with the number there is a diffrent problem. On the page the case number shows two leading zeros. 00408374. The case number displayed using an alert message is 408374. Therefore when the case number is passed to APEX it cannot find the record. I tried 

new String({!Case.CaseNumber} but that didn't work either. 


Can someone please help me figure out what is wrong. All I want to do is pass the Id of the Case record to the APEX class using sforce.apex.execute("MyClass","MyMethod",{id:caseId});


Thanks in advance.






var caseId = "{!Case.Id} ";


(with quotes)


by now you might have figured this out. But I will post it anyways, if others are stuck. 


try this: