我已经创建了一个POST方法REST服务,并试图在visualforce页面中通过JavaScript中的sforce.connection.remoteFunction调用该服务。
var request_url = 'https://test.salesforce.com/services/oauth2/token';
var result = sforce.connection.login("myloginid@mymail.com", "mypassword+mysecurityToken");
此处的登录ID,密码和安全令牌与我必须用于登录salesfroce帐户的ID和密码不同
var sessionId= sforce.connection.sessionId;
sforce.connection.init(sessionId, request_url);
sforce.connection.remoteFunction({
url : request_url,
type : "post",
async : false,
requestHeaders: {"Authorization":"Bearer "+sessionId, "Content-Type":"application/json","Connection":"Keep-Alive"},
data :requestData,
onSuccess : function(response) {
console.log(success);
},
onFailure: function(response) {
console.log(response.responseText);
}
});
但是回复是错误401未经授权。我的请求中是否有任何遗漏?
我已经看到了两个解决方案: -
2。https://salesforce.stackexchange.com/questions/13607/how-to-call-apex-rest-api-from-javascript
但这些解决方案对我不起作用。请帮帮我..