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
alkemacsalkemacs 

Unexpected token } when I click on a onClickJavascript Button

Hi ! 

I tried several time to create a custom onclickJavascript button in Salesforce with several codes but I got the same error all the time :

Unexpected token }

Here, you can find my code : 

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

var urlcio = 'https://id:password@trck.customer.net/api/v1/customers/path';
var envelope = '{"name":"registration","data":{"price": "23.45", "product": "socks"}}';
 
sforce.connection.remoteFunction({
url : urlcio,
requestHeaders: {"Content-Type:application/json"},
requestData : envelope,
method : 'POST',
onSuccess : function(response) { alert('OK: '+response); },
onFailure : function(response) { alert('ERROR: '+response); },
});

Can you help me to solve this please ?

 

 

Best Answer chosen by alkemacs
jigarshahjigarshah
alkemacs,

You need to enclose the Content-Type key and its associated value with the double quotes since they are key value pairs. Use the below used line of code as follows
requestHeaders: {"Content-Type":"application/json"},
Once you do so, you may recieve a "400 (Unauthorized or inactive endpoint, please add 'https://trck.customer.net' to Setup -> Security Controls -> Remote Site Settings)" error. You will need to whitelist the external endpoint url within Salesforce by adding it to Remote Site Settings. You can do so by adding the the url to Setup -> Security Controls -> Remote Site Settings.

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.

All Answers

jigarshahjigarshah
alkemacs,

You need to enclose the Content-Type key and its associated value with the double quotes since they are key value pairs. Use the below used line of code as follows
requestHeaders: {"Content-Type":"application/json"},
Once you do so, you may recieve a "400 (Unauthorized or inactive endpoint, please add 'https://trck.customer.net' to Setup -> Security Controls -> Remote Site Settings)" error. You will need to whitelist the external endpoint url within Salesforce by adding it to Remote Site Settings. You can do so by adding the the url to Setup -> Security Controls -> Remote Site Settings.

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
This was selected as the best answer
alkemacsalkemacs
Thank you a lot !