Search Results

Wednesday, May 04, 2016

Testing network connectivity from Salesforce

One of the challenges with consuming the web-service from SalesForce is that lack of tools, like telnet and ping, to test the network connectivity.

But luckily we code execute anonymous code in SalesForce from Developer console. Here are the steps to test web-service from sales-force.

Register URL 

All the URLs must be registered in SalesForce remote site settings before being called by the code.

  • Go to Setup > Security Controls > Remote Site Settings
  • Click on New Remote Site, enter the following and click Save
    • Remote Site Name: XX_TEST
    • Remote Site URL: http://domainhost/
  • Click Save

SalesForce Test Code

  • Go to the Developer Console 
  • Navigate Debug > Open Execute Anonymous Window  (Ctrl + E)
  • Execute the following code
  • Logs should show up in the Query Results Window

String soapEndpoint = 'https://blabla/test';
String soapBody = 'soap envelope';

HttpRequest req = new HttpRequest();
Http http = new Http();
HttpResponse resp = new HttpResponse();

//add Request header
req.setHeader('Content-type', 'text/xml; charset=utf-8');
req.setHeader('SOAPAction', 'namesspace for wsdl');

// add the endpoint to the request
try {
System.debug('Sending request');
resp = http.send(req);
}  catch(System.CalloutException e) {
System.debug('Callout error: '+ e);

Post a Comment