fork download
  1. public class SalesforceIntegrationExample {
  2.  
  3. public static void getExternalData() {
  4. // 1. Create the 'Phone' (Http object)
  5. Http http = new Http();
  6.  
  7. // 2. Prepare the 'Call' (HttpRequest object)
  8. HttpRequest request = new HttpRequest();
  9.  
  10. // 3. Dial the number (The Endpoint URL)
  11. request.setEndpoint('https://g...content-available-to-author-only...g.org/api/temperature-api');
  12.  
  13. // 4. Tell them what you want (The Method: GET means "send me info")
  14. request.setMethod('GET');
  15.  
  16. // 5. Make the call and wait for the Answer (HttpResponse object)
  17. HttpResponse response = http.send(request);
  18.  
  19. // 6. Check if the call was successful (Status Code 200)
  20. if (response.getStatusCode() == 200) {
  21. // Success! Print the data to the console
  22. System.debug('Data received: ' + response.getBody());
  23. } else {
  24. // Something went wrong (e.g., 404 - Not Found)
  25. System.debug('Error! Status Code: ' + response.getStatusCode());
  26. }
  27. }
  28. }
  29.  
Success #stdin #stdout #stderr 0.02s 10040KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #SalesforceIntegrationExample
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #SalesforceIntegrationExample (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #the
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #the (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:21)
stderr
./prog:3: parse error, expected '}'
./prog:22: expected expression