Skip to content

Instantly share code, notes, and snippets.

@tvaidyan
Created September 15, 2021 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvaidyan/37e56862f0a74942ffc6f0ff46bc69d8 to your computer and use it in GitHub Desktop.
Save tvaidyan/37e56862f0a74942ffc6f0ff46bc69d8 to your computer and use it in GitHub Desktop.
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