[SalesForce] Setting up a connection to an external web service

I haven't worked with web services and was hoping someone could provide some guidance. I have read the API documentation for this external web service API and I need some help understanding how I can accomplish the following. The API documentation states:

A connection to the service is required before calling any function. This requires setting up a binding and having a valid address for the service. The sample has a function that will configure the binding, but a valid address will have to be supplied

So, I need the URL endpoint (web address to the service). Do I have to setup a remote site in Salesforce? What is the binding? The documentation doesn't include any sample.

I am only using this API once to pull data and insert into several objects in Salesforce. I understand from the documentation what methods I need to call and the parameters I need to pass, but since this is a one time pull I'm wondering what would be the easiest approach? HTTP Request/Response, parse the XML and insert using execute anonymous from the developer console?

Sorry for the novice questions. Just trying to get my head wrapped around web services.

Thanks.

Best Answer

The first step before making a webservice callout is configuring Remote site settings Salesforce. This is a way of telling Salesforce that this is a valid or authorized URL. For example, if the endpoint where you will be hitting is http://www.mapquestapi.com?APPID=dvdbdfgdf123bbf, then you must add http://www.mapquestapi.com in your remote site settings. Adding only base url of the endpoint would do. You won't be able to make any callouts until you add the url in the remote site settings.

Now, since you are fetching data from an external source, choosing REST or SOAP depends upon the volume of data. If you use REST, it will be easier to maintain since it's lightweight and can also be used in mobility. I personally favor using JSON with REST callout. However, getting the response in JSON format has quite some limitations. We need to take care if the heap size governor limit in Salesforce since your JSON response may be quite huge. Anyway, if you make this callout asynchronously then this limit is doubled (from 6 MB to 12 MB), so hitting that limit would be quite difficult.

There are three classes - HTTP, HttpRequest and HttpResponse that can be utilized to form your request and retrieve your response. You should go through these three classes to understand the functionality better.

Hence, technically you would be needing two classes - one for creating the request and other for typecasting the response into the format you need. If you use JSON, you can simply serialize and deserialize the JSON string and get the work done.

If you have specific questions related to the above, you can post them in comments. We can discuss further.

Related Topic