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();
req.setEndpoint(soapEndpoint);

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

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

No comments :