You need to sign in to do that
Don't have an account?
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 ?
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 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
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 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.