You need to sign in to do that
Don't have an account?
Kevin Languedoc
Call Apex Webservice from Javascript in VF page
I need to test the communication between javascript in a VF page that is rendered from a button on a open case document and an Apex webservice that is supposed to send an e-mail. However I get the impression that the web service is never called. So I created a small dummy webservice, called WSReturn to receive a name and return a string. I am trying to dtermine if the problem is in the javascript code or the Apex code.
Browser: Chrome, Version 42.0.2311.90 (64-bit) on a Mac
The javascript function sayHelloService is called on the window.onload event. However I am getting this error message:
Refused to set unsafe header "User-Agent"
send @ connection.js:593
sforce.SoapTransport.send @ connection.js:1012
sforce.Connection._invoke @ connection.js:1727
sforce.Apex.execute @ apex.js:60
sayHelloService @ Form1747web?scontrolCaching=1&id=50055000000fkiR&isdtp=vw&nonce=dcb74e9d3d4fd43461bc263b172a1a02c72…:41
Javascript code:
Apex Code:
Browser: Chrome, Version 42.0.2311.90 (64-bit) on a Mac
The javascript function sayHelloService is called on the window.onload event. However I am getting this error message:
Refused to set unsafe header "User-Agent"
send @ connection.js:593
sforce.SoapTransport.send @ connection.js:1012
sforce.Connection._invoke @ connection.js:1727
sforce.Apex.execute @ apex.js:60
sayHelloService @ Form1747web?scontrolCaching=1&id=50055000000fkiR&isdtp=vw&nonce=dcb74e9d3d4fd43461bc263b172a1a02c72…:41
Javascript code:
function sayHelloService(){ var hello = sforce.apex.execute("WSReturn", "Hello", {name:'Kevin'}); sforce.debug.log(hello); }
Apex Code:
global class WSReturn { webservice static String Hello(String name){ String sayHello; sayHello = 'Hi ' + name; System.debug('sayHello'); return sayHello; } }
You should be able to still use it as a webservice for other use cases as well in this scenario.
All Answers
You should be able to still use it as a webservice for other use cases as well in this scenario.
I didn't think of that. That is a great solution.
Thanks
Kevin