Skip to content

Instantly share code, notes, and snippets.

@pbattisson
Created August 16, 2020 13:28
Show Gist options
  • Save pbattisson/3b47838a64dd6be312b3c46f8c5afd86 to your computer and use it in GitHub Desktop.
Save pbattisson/3b47838a64dd6be312b3c46f8c5afd86 to your computer and use it in GitHub Desktop.
public static void sendMessage(Message msg) {
HttpRequest req = new HttpRequest();
req.setMethod('POST');
//req.setEndpoint('https://api.learnsfdevwithapex.com/messages');
req.setEndpoint('callout:LearningSFDevAPI/messages'); //This is for the final version at the end of the chapter
req.setBody(JSON.serialize(msg));
req.setHeader('X-Auth-Token', 'SEE_BOOK_FOR_VALUE');
req.setHeader('content-type', 'application/json');
Http http = new Http();
HttpResponse res = http.send(req);
if(res.getStatusCode() != 200) {
throw new LearningSFDevAPIException('API callout returned with a status of ' + res.getStatus());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment