We have a VF page. From that page, we are trying to download standard Salesforce attachment using XMLHttpRequest in javascript. We are doing GET request with attachment download URL as the endpoint. But unfortunately, we are getting error "Access to XMLHttpRequest at [endpoint] from origin [Visualforce URL] has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource". We also added endpoint as CSP and visualforce page URL as CORS in the Salesforce. But still getting same error.

  • Visual force is served from a different domain and Salesforce standard content from different domain. You should try using Ajax toolkit remoteFunction which acts a s a server side proxy. developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/… – manjit5190 Apr 5 at 5:41
  • @manjit5190 I just tried remoteFunction but getting bad request error. In that link, there is no details about what i need to pass as request headers. – Anil Meghnathi Apr 5 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.