I have created a GET method REST service and trying to Ajax call the service through sforce.connection.remoteFunction
from JavaScript. Able to get the Session Id and it hitting the service. But the response was Error 401 Unauthorized
. Is there anything I'm missing in the request?
Note: I'm Passing the session Id in the request header.
Attaching my Script:
<script type="text/javascript">
window.onload = setupPage;
function setupPage() {
var result = sforce.connection.login("myloginmailid", "pwd+security token");
sforce.connection.init(result.sessionId, 'Service URL');
<!-- Salesforce Remote Connection-->
sforce.connection.remoteFunction({
url : "Service URL",
requestHeaders: {"Authorization":"Bearer"+__sfdcSessionId, "Content-Type":"application/json", "Connection":"Keep-Alive" },
method: "GET",
onSuccess : function(response) {
alert("Success" +response);
},
onFailure : function(response) {
alert("Failed" + response)
}
});
</script>
sforce.connection.sessionId = __sfdcSessionId
.