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
George AdamsGeorge Adams 

"Unexpected identifier" error from Detail Page Button

Hi all,

I'm creating a Detail Page Button that runs through various methods in an apex class. To get it up and running, I'm simply trying to return the current caseID in a pop-up. Here's the button code I'm using:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 

var thisCase = {!Case.Id}; 

var result = sforce.apex.execute( 
"logHearingResult",       // class 
"changePriority",         // method 
{currentCase: thisCase}); // method arguments 


alert(result + " is the current caseID."); //response

And here is the apex class:
 
global class logHearingResult{

  WebService static Integer doMath(Integer number1, Integer number2) {
    
    integer mathResult;
	mathResult = number1 + number2;
    
    return mathResult;
      
  }
    
    
  WebService static Id changePriority(Id currentCase) {
   
    Set<Id> caseIds = new Set<Id>();
      
    caseIds.add(currentCase);
      
    List<Case> results = [
        select Id
        from Case
        where Id in :caseIds
    ];	
    
    id caseIdToReturn;
    caseIdToReturn = results.get(0).Id;
      
    return caseIdToReturn;
      
  }
    
}

When I click the button, I just get the error: "Unexpected identifier"

I posted both because I'm not sure if this is a problem with my javascript or apex code. There's also that unused method doMath in the class.

Eventually I want the apex class to (1) update a field on the current case (change Status to 'Closed'), (2) open the case email attachments associated with the current case in a new window, (3) create a record in a custom object with some info already filled out (based on some fields on the case), and (4) copy the case email attachments associated with the current case to the newly created record.

I'm assuming most of the above is outside the scope of this question, but I'm trying to get started on that path.

And help is appreciated. Thanks!
Best Answer chosen by George Adams
Shashikant SharmaShashikant Sharma
Hi Mathew,

No need to remove the post. It will help others having same issue so you could mark it as solved instead.

Just putting some explaination to your solution. 
 
var thisCase = {!Case.Id};

this statement in Datiled Button java script execution was giving exception. So it was givng you error message "Unhandled Exception". 

Solution for this is to have assinged values in quotes like
 
var thisCase = "{!Case.Id}";

In order get proper error message you could do Exception Handling in Java Script like
 
try {
// put your java script code here
}
catch(e) {
alert( ' Error, Please Contact Administrator ');
}

Thanks
Shashikant

All Answers

George AdamsGeorge Adams
Well, it was as simple as changing this:
 
var thisCase = {!Case.Id};

...to this:
 
var thisCase = "{!Case.Id}";

I can remove the post if necessary.

If anyone knows were I might get started on the other aspects of the apex class, please let me know!

Thanks.
Shashikant SharmaShashikant Sharma
Hi Mathew,

No need to remove the post. It will help others having same issue so you could mark it as solved instead.

Just putting some explaination to your solution. 
 
var thisCase = {!Case.Id};

this statement in Datiled Button java script execution was giving exception. So it was givng you error message "Unhandled Exception". 

Solution for this is to have assinged values in quotes like
 
var thisCase = "{!Case.Id}";

In order get proper error message you could do Exception Handling in Java Script like
 
try {
// put your java script code here
}
catch(e) {
alert( ' Error, Please Contact Administrator ');
}

Thanks
Shashikant
This was selected as the best answer