In short how to do an apex callout from Class..
Apex class:
*******************************************
global class with sharing ApexCallout{
public void callout()
{
//Construct a HTTP Request
HttpRequest req = new HttpRequest() ;
string strUrl=’**********Place your Remote Site Address here**********”;
//Before making this callout, you need to add Remote site address in the Remote Site Settings of your Organization..
//Setting Endpoint URL to HTTP request
req.setEndpoint(strUrl);
//Set the request type
req.setMethod(‘GET’);
//HTTP object creation
Http http = new Http();
//Sending the Req throgh HTTPResponse object.
HTTPResponse res = http.send(req);
//System.debug(res.getBody());
//System.debug(res.getStatus());
}
}
If you need to pass some parameters in the method, you can do it..
by changing the method to method with arguments.
You can call this method from trigger also..

Written by 

Salesforce MVP | Lightning Champion | 16x Salesforce Certified | Application Architect | 6x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*