I'd like to use the name of the opportunity, which a case is being created from, as the case Subject, for easy reference.

My cases are being created using a custom button & JavaScript. I can't find an example of code which converts the Opportunity Name into a string anywhere so that I can then use this value to populate Subject, is this possible?


var recToCreate = new sforce.SObject("Case");  
recToCreate.OwnerId = "00G18000000Ntra";  
recToCreate.Opportunity__c = '{!Opportunity.Id}';  
recToCreate.AccountId = '{!Opportunity.AccountId}';  
recToCreate.Subject = {!Opportunity.Name};  

var result = sforce.connection.create([recToCreate]); 

  if(result[0].success == "true"){
      alert("An Error has Occurred. Error:" + result[0].errors.message);
   alert("An Error has Occurred. Error:" + e);

The above returns "Unexpected identifier"

  • Can you share your previous code so that we may help you ? Commented Apr 12, 2015 at 14:56
  • Sure, I've added it.
    – Alex S
    Commented Apr 12, 2015 at 14:59
  • 2
    It looks like you forgot quotes around {!Opportunity.Name}. Commented Apr 12, 2015 at 15:03
  • Alex if Namfuak answer resolved your issue .Pls ask him to add as answer Commented Apr 12, 2015 at 15:08
  • @Namfuak if you hadn't realized already, you've answered my question, please feel free to add the answer.
    – Alex S
    Commented Apr 12, 2015 at 15:09

1 Answer 1


You forgot quotes around {!Opportunity.Name}. The line should read:

recToCreate.Subject = '{!Opportunity.Name}';  

Without the quotes, the browser interprets the name of the Opportunity as an identifier, which is why you get the error you are reporting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .