+ Start a Discussion

API Call Issue - Filling fields from external sources



I am trying to add in a field from an external API source and I am wondering the best way to do and what I would need.


I have found a website whereby if I construct a URL from pieces of data from SFDC it will return a list of fields, one of which I want to pull into my platform.


So the URL I construct brings back geo-location information about a specific latitude and longitude. I want to grab one field from a list of fields presented back on a web page. This page can be constructed in JSON or XML which I can control.


This is all releated to a custom object but acts very much like a Case would.


So on the insert of this case data through the API I want a trigger to go away and pull back one field from the URL API to complete the geographical information on the case


What call would I use to going out of Salesforce to do that? Any thoughts on how I call and insert the new data into my custom object? I am assuming APEX can do this and return me a value?


Hope that all meakes sense.


I look forward to hearing your suggestions.



You can call an external web service or HTTP/HTTPS Url from apex. Refer to http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts.htm for more information on how to go about doing this.


Thanks for that.


Here is where I am up to.


trigger LatLong on Incident__c (before insert, before update) {

// Pass in the endpoint to be used using the string url  
  public String getContent(String url) {

// Instantiate a new http object  
    Http h = new Http();

// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint  
    HttpRequest req = new HttpRequest();

// Send the request, and return a response  
    HttpResponse res = h.send(req);
    return res.getBody();



What I now need to do is pick out a specific piece of information form that html and insert it into an existing field on a custom object.


I am sure either the upsert or insert command does this but I have no idea how to 'pick' out the elements that I need using APEX from the html that has been returned.


Any ideas?


I think I need to be using a DOM class perhaps?