Monday, 24 February 2014

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):
  1. Remove extra port types:
  1. Remove extra bindings:
  1. 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;
    }
}
Create a new page:

<apex:page controller="MyController"> Test page <apex:pageBlock title="Weather icons"> <table> <apex:repeat value="{!elements}" var="item"> <tr> <td>{!item}</td> <td><img src="{!elements[item]}" /></td> </tr> </apex:repeat> </table> </apex:pageBlock> </apex:page>


Now we can test the new page:
It was pretty easy, huh? :)

Sport statistics

I have a strong interest in data analysis and notice some interesting facts from everywhere.
It was a curious thing for me to see how Winter Olympics 2014 medal count correlate with the sponsor investments to the teams and found the following:



So, the most profitable team was from Netherlands and sponsorship (and advertisement) was the most effective for this team.
They just have amazing results and every second athlete in this team has a medal. Very effective team of 41 athlete was built - they received 24 medals in total.
Belorussian team was fantastic in terms of Gold medals.

Sources of information:
http://en.wikipedia.org/wiki/2014_Winter_Olympics
http://www.sochi2014.com/en/medal-standings