function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Surendra nuneSurendra nune 

Acess URL.getSalesforceBaseUrl().toExternalForm() from execute anonymous

Hi,

I need to set the CORS headers to an external system from Salesforce using http callouts.

To get the current request URL I know that we use,
 
URL.getSalesforceBaseUrl().toExternalForm()

But I need the url of visualforce page and Site in an apex controller which is not associated to any vf page for setting the cors headers. 
How can I acheive this?


 
NagaNaga (Salesforce Developers) 
Hi Surendra,

CORS loosens the browser Same Origin policy in a controlled manner, allowing JavaScript loaded from one origin, for example, https://myapp.herokuapp.com, to access an API in another, for example, https://na15.salesforce.com, by allowing the API server to provide a list of origins that may be permitted access.

Please follow the below link for more information

https://developer.salesforce.com/blogs/developer-relations/2015/01/spring-15-preview-cors-force-com-rest-api.html

Best Regards
Naga kiran