function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
manjirimanjiri 

Problem in Calling Yahoo web Service from Apex class

Hi,

I want to call Yahoo web service through REST protocol from my apex code.

I am using following example given in apex language reference guide. I have just replaced my url in the code.

public class HttpCalloutSample {
// Pass in the endpoint to be used using the string url
public String getContent() {
// 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();
String url = 'http://travel.yahooapis.com/TripService/V1.1/tripSearch?appid=YahooDemo';
req.setEndpoint(url);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
return res.getBody();
}
}

I am calling following line from my S-Control (in my javascript function)
var success = sforce.apex.execute("HttpCalloutSample", "getContent", {});

I am getting following exception.

faultcode soapenv:Client
faultstring No operation available for request {http://soap.sforce.com/schemas/package/HttpCalloutSample}getContent, please check the WSDL for the service.

So what is the problem? Is it a right way?
Does anyone have any example code or syntax show how I would make that call?

Thanks
lodoss118lodoss118
convert your class as a web service i think?
lodoss118lodoss118
This should work :-


[source]

        global class HttpCalloutSample
        {
                // Pass in the endpoint to be used using the string url 
                WebService static String getContent()
 
                {
                        // 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();
                        String url = 'http://travel.yahooapis.com/TripService/V1.1/tripSearch?appid=YahooDemo';
                        req.setEndpoint(url);
                        req.setMethod('GET');
                        // Send the request, and return a response
                        HttpResponse res = h.send(req);
                        return res.getBody();
                }
        }

[/source]
Chris_LearningChris_Learning
I tried to autopopulate a field in the account with the content of the Web Service.
 
public class MyHelloWorld {

public static void addHelloWorld(Account[ ] accs) {
   for (Account a:accs) {
     if (a.Hello__c != HttpCalloutSample.getContent())
     a.Hello__c = 'World';
}
}

}

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger helloWorldAccountTrigger caused an unexpected exception, contact your administrator: helloWorldAccountTrigger: execution of BeforeInsert caused by: System.CalloutException: Callout from triggers are currently not supported.: Class.HttpCalloutSample.getContent: line 14, column 44
 
Can you please show me how to populate the content of the web service into a field?
 
 
manjirimanjiri
thank you very much :)
Now we are able to call webservice.