Skip to content

Instantly share code, notes, and snippets.

Embed
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) {
try{
HttpRequest request = new HttpRequest();
request.setMethod('POST');
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');
}else{
System.debug('Request Error: ' + String.valueOf(response.getStatusCode()) + response.getBody());
}
System.debug('completed');
}
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