Suppose you need to fetch some data from a remote website inside a Salesforce.com APEX Code. This can be any type of text ranging from text to XML content, which you want to use to perform additional tasks based on. This comes in particularly handy if you need to do some sort of an integration with a Legacy System which cannot produce a structured WSDL Web Service.
Here is how you can accomplish this:
1. Create an APEX Class called "HttpCalloutSample", with the following code:
Now let's call this APEX Class using Eclipse Force.com IDE "Execute Anonymous" code block feature (or if you prefer to call it from within an APEX Trigger you can do that too). Your calling code would look something like this:
The URL is basically the URL of the content you wish to fetch from the Remote Server. In this case I am using the URL of the Distribution Agreement of one of my open source projects, which is a simple text file containing some text. The first time you execute the code, you will see this error:
10:15:31.238 (238577000)|USER_DEBUG||DEBUG|Definition of Freeware
Freeware distribution gives users a chance to try software and continue to us ... (the rest of the content)
I hope others find this blog entry helpful.
DigiOz Multimedia, Inc.