+ Start a Discussion
Stavros McGillicuddyStavros McGillicuddy 

Invalid or Unexpected Token Error

I am trying to update the Sample_QB_Error__c field with Hello
This code throws "an Invalid or unexpected token"  

Thanks
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 
var record = new sforce.SObject("Opportunity"); 
record.Id = ‘{!Opportunity.Id}’; 
record.Sample_QB_Error__c ="Hello"; 
sforce.connection.update([record]); 
window.location.reload();

 
Best Answer chosen by Stavros McGillicuddy
@Karanraj@Karanraj
It's just problem with the single quotation mark in the code.
Try the below updated code
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
record.Sample_QB_Error__c ="Hello";
sforce.connection.update([record]);
window.location.reload();

 

All Answers

@Karanraj@Karanraj
It's just problem with the single quotation mark in the code.
Try the below updated code
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
record.Sample_QB_Error__c ="Hello";
sforce.connection.update([record]);
window.location.reload();

 
This was selected as the best answer
Stavros McGillicuddyStavros McGillicuddy
SPOT ON!
That fixed it but, I can't see the difference between your code and mine (scratching head)
Thank you Karanajs. 
 
@Karanraj@Karanraj
Check the line number 4. The difference is in the single quotation marks 
Stavros McGillicuddyStavros McGillicuddy
Ahh.. I see it now. Thank you so much!
Kory Leavitt 5Kory Leavitt 5

Friends, could you help me with this code and that is resulting in the same error?

 

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


// Does a post request 

_SendExtend.postAjax = function (url, callback, data) { 
var ajaxRequest = _SendExtend.getAjaxRequest(callback); 
ajaxRequest.open("POST", url, true); 
ajaxRequest.setRequestHeader("Content-Type", "application/json"); 
ajaxRequest.setRequestHeader("Connection", "close"); 
ajaxRequest.send("data=" + encodeURIComponent(data)); 
}; 

// Returns an AJAX request obj 
_SendExtend.getAjaxRequest = function (callback) { 

var ajaxRequest; 

try { 
ajaxRequest = new XMLHttpRequest(); 
} catch (e) { 
try { 
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (e) { 
try { 
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
} catch (e) { 
return null; 




ajaxRequest.onreadystatechange = function () { 
if (ajaxRequest.readyState == 4) { 
// Prob want to do some error or response checking, but for 
// this example just pass the responseText to our callback function 
callback(ajaxRequest.responseText); 

}; 


return ajaxRequest; 

}; 


var _SendExtend = _SendExtend ? _SendExtend : new Object(); 


function processResponse(responseText) { 
// Response text is a json: 
//var obj = JSON.parse(responseText) // won't work all browsers, there are alternatives 

alert(‘Call succeeded ’ + responseText); 


var jsonToPost = “"; 
//Here is where the variable would be replaced // + '[CRMAccountId]'; 
//TEST Environment 
var url = "https://boomiqa1.sanjuan.avalara.com/ws/rest/provisioning/admin/v1/extend/0011900000QNFO9AAP /“; 
//PRODUCTION Environment 
//var url = "https://boomiprod1.sanjuan.avalara.com/ws/rest/provisioning/admin/v1/extend/" + “[CRMAccountId]"; 

_SendExtend.postAjax(url, processResponse, jsonToPost);

 

We're simply trying to send the Account ID to an external end point.

Zahra BukhariZahra Bukhari
hi @karanraj I have a similar issue, but nothing seems to be working. I'm java newbie, but have had others look at my script, and everyone says it looks good. An engineer friend tested out this script and even added the statement "alert("Did We Do Anything)", which never triggred, so we think the script isnt even getting executed. Our assumption is the first statement is wrong... any thoughts here?

{!requireScript("/soap/ajax/40.0/connection.js")} 
alert("DID WE DO ANYTHING?"); 
varselectedAccountIds = {!GETRECORDIDS($ObjectType.Account)}; 
varaccountsForUpdate = []; 
if (selectedAccountIds[0] == null) { 
alert(“You must select at least one record”); 
} else { 
for (vari = 0; i < selectedAccountIds.length; i++) { 
var account = new sforce.SObject(“Account”); 
account.Id = selectedAccountIds[i]; 
account.Target_Account__c = TRUE.toISOString(); 
accountsForUpdate.push(account); 


varsaveResult = sforce.connection.update(accountsForUpdate); 
location.reload(true);
Raja JammulaRaja Jammula
Javascript: I am getting Unexpected token error for below code can you please help:

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

var obj;
var task5;
var recordtypeid;
var followup;
var recordtypefol;
if("{!$Profile.Name}" == "TX1" || 
"{!$Profile.Name}"== "TX2"||
"{!$Profile.Name}"== "WX1"||
"{!$Profile.Name}"== "WX2"||
"{!$Profile.Name}"== "WX3"||
"{!$Profile.Name}"== "WX4"|| 
"{!$Profile.Name}" == "CC"){

obj='a1r';
}
else{
obj='00T';
}
alert(obj);

var url='/'+obj+'/e?CF00N50000002CzJi={!Account.Name}&CF00N50000002CzJi_lkid={!Account.Id}&retURL=/{!Contact.Id}&title=Call&who_id={!Contact.Id}&00N50000002D0zP={!User.Primary_Product__c}'
if(obj=="a1r")
{
url+='&followup=1&tsk5=call'
}

if(obj=="00T"){
if("{!$Profile.Name}" == "WI" && ("{!$UserRole.Name}"=="AS - E"||"{!$UserRole.Name}"=="AS - M"||"{!$UserRole.Name}"=="AS - T")){
task5="Meeting";
recordtypeid="0123B0000008tqK";
followup='';
recordtypefol="0123B0000008tqK";
}elseif("{!$Profile.Name}" == "WI Corporate Sales") {
task5="call";
recordtypeid="01250000000HiDD";
followup ="1";
recordtypefol="01250000000HiDD"; 
}else{
url+='&tsk5='+task5+'$tsk12=Completed'+'&RecordType='+recordtypeid+'&RecordType_fu='+recordtypefol+'&followup='+followup+'&tsk4={!TODAY()}'
}
}
else{
url+='&followup=1&tsk5=call'
}

window.parent.open(url, "_self");
Kunal Bhatia 11Kunal Bhatia 11
Hi all,

I am trying to write a simple JS button on opportunity to toggle a picklist based on its existing value. When I run it I get an error.

Check whether Sync Flag not set to 'Sync' and update it to 'To Be Sync'. Not sure why I am getting this error. Please help! Thanks!!

Button:
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}';
if(record.Sync_Flag__c === 'Sync') 
{
alert( "Hi " + '{!$User.FirstName}' + ", " + "This opportunity is already synced successfully to Netsuite. Have a good day!);
}
else
{
record.Sync_Flag__c = "To Be Sync";
sforce.connection.update([record]); 
parent.location.href = parent.location.href;
}

Error:
Error message

@Karanraj
@Stavros McGillicuddy