Salesforce Working with External Systems Making an outbound callout

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

This is an example on how to call a web service from salesforce. The code below is calling a REST based service hosted on data.gov to find farmers markets close to the zipcode.

Please remember in order to invoke a HTTP callout from your org, you need to tweak the remote settings for the org.

string url= 'http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=10017';
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint(url);
req.setMethod('GET');
res = h.send(req);
System.Debug('response body '+res.getBody());


Got any Salesforce Question?