I've been looking all over the place to figure out how to approach this. I'm trying to call a web service (services/apexrest) from the same org. I'm recieving the following error:

XMLHttpRequest cannot load https://cs45.salesforce.com/services/apexrest/RimsSalesforceConnectRemote. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'https://c.cs45.visual.force.com' is therefore not allowed access. The response had HTTP status code 401.

I noticed that the origin is different than the target.

  • Is there no way to call this web service via JavaScript?
  • Is this simply unsupported functionality?

I am able to make successful calls via workbench.developerforce.com so I'm a bit confused. I do not want this API to be publicly accessible, so I opted to not associated with a Site.

What is also interesting is that the error alludes to a CORS issue, but the 401 code according to Salesforce has more to do with a bad token.

Update 1* As suggested, I leveraged the sforce.connect.remoteFunction with a promise to call the Apex rest web service. Unfortunately due to the requirements, I'm now bumping into a callout depth threshold:

[{"errorCode":"APEX_ERROR","message":"System.CalloutException: Callout loop not allowed\n\nClass.RimsSalesforceConnectRemote.sendRequest: line 19, column 1\nClass.RimsSalesforceConnectRemote.doPost: line 33, column 1"}]

To clarify my architecture is as follows: Client -> Apex Rest web service -> 3rd Party API

So far I've tried to make direct calls to the Apex Rest web service via the $http AngularJS module and now via the sforce.connection.remoteFunction.

I definitely didn't think that simply calling the Apex Rest web service would be such a pain. Testing via developer workbench was so simply. Hair is falling out.



Browse other questions tagged .