Quick hands-on tutorial of consuming external web services from SalesForce
Recently I had to perform some research of SalesForce in order to reuse some web services on SalesForce application.
Previously I had absolutely no experience of using SalesForce, so many features were unknown for me. But surprisingly the task was not so difficult.
I used freely available web service for my research:
I used this method as an example:
Add external web service URL into “Remote Site Settings” (it is important because no external web services can be used by default):
Download Weather WSDL:
Modify WSDL file: remove multiple parameters (multiple ports, bindings, services sections of WSDL file are not supported by SalesForce Apex classes):
- Remove extra port types:
- Remove extra bindings:
- Remove extra services:
Generate Apex class for WSDL:
Create a new controller:
public class MyController {
public Map getElements() {
wsCdyneComWeatherws.WeatherSoap info = new wsCdyneComWeatherws.WeatherSoap();
info.endpoint_x = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx';
wsCdyneComWeatherws.ArrayOfWeatherDescription data = info.GetWeatherInformation();
Map ret = new Map();
for (wsCdyneComWeatherws.WeatherDescription item: data.WeatherDescription) {
ret.put(item.Description, item.PictureURL);
}
return ret;
}
}
public Map
wsCdyneComWeatherws.WeatherSoap info = new wsCdyneComWeatherws.WeatherSoap();
info.endpoint_x = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx';
wsCdyneComWeatherws.ArrayOfWeatherDescription data = info.GetWeatherInformation();
Map
for (wsCdyneComWeatherws.WeatherDescription item: data.WeatherDescription) {
ret.put(item.Description, item.PictureURL);
}
return ret;
}
}
Create a new page:
Now we can test the new page:
It was pretty easy, huh? :)
No comments:
Post a Comment