Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Hello World Apex HTTP Callout Example
public class DemoTriggerHandler {
@future (callout=true)
public static void sendTestRequest(string field1, string field2, string field3) {
HttpRequest request = new HttpRequest();
request.setEndpoint("my external api url goes here");
request.setBody('{"message":"Hello World"}');
HttpResponse response = new HttpResponse();
Http http = new Http();
response = http.send(request);
if (response.getStatusCode() == 200) {
System.debug('I got a 200 OK from the external system');
System.debug('Request Error: ' + String.valueOf(response.getStatusCode()) + response.getBody());
catch(System.CalloutException e){
System.debug('Error-' + e.getMessage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment