AJAX Proxy

Some browsers don't allow JavaScript code to connect to external servers directly. Therefore, you may need to send requests through the AJAX proxy.

To use the AJAX proxy, you must register all external services in the Salesforce user interface. From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.

For security reasons, Salesforce restricts the outbound ports you may specify to one of the following:

  • 80: This port only accepts HTTP connections.
  • 443: This port only accepts HTTPS connections.
  • 1024–66535 (inclusive): These ports accept HTTP or HTTPS connections.

Note

The AJAX proxy is part of the AJAX Toolkit. Access it using remoteFunction defined in connection.js. You can specify any HTTP method in remoteFunction, for example HTTP GET or POST, and it will be forwarded to the external service.

The following examples illustrate typical approaches for GET and POST:

GET Example:

sforce.connection.remoteFunction({
                   url : "http://www.myExternalServer.com",
                   onSuccess : function(response) {
                          alert("result" + response);
                      }
               });

POST Example:

var envelope = ""; //request envelope, empty for this example
            sforce.connection.remoteFunction({
                   url : "http://services.xmethods.net:80/soap",
                   requestHeaders: {"Content-Type":"text/xml",
                          "SOAPAction": "\"\""
                      },
                   requestData: envelope,
                   method: "POST",
                   onSuccess : function(response) {
                          sforce.debug.log(response);
                      },
                   onFailure : function(response) {
                          alert("Failed" + response)
                      }
               });