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
sultansultan 

How to make a call out from normal Apex class?

Best Answer chosen by sultan
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Raju,

You can perform callout as
public class HttpCalloutSample {

// 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();
    req.setEndpoint(url);
    req.setMethod('GET');

// Send the request, and return a response
    HttpResponse res = h.send(req);
    return res.getBody();
  }
}
Please go through http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_callouts.htm for more information.

Thanks,
N.J

All Answers

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Raju,

You can perform callout as
public class HttpCalloutSample {

// 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();
    req.setEndpoint(url);
    req.setMethod('GET');

// Send the request, and return a response
    HttpResponse res = h.send(req);
    return res.getBody();
  }
}
Please go through http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_callouts.htm for more information.

Thanks,
N.J
This was selected as the best answer
AshwaniAshwani
There in normal or abnormal Apex. Callout is basically use a set of Apex classes used to callout to external system. There are twoways of callout Rest and Soap.

Rest class include: HttpRequest, HttpResponse, Http etc.
Soap are defined by parsing wsdl in Apex. A simple caalout has already been given in post above.