-
-
Save TheShubhamVsnv/25b34e941e3f7949f14b964bac0177b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GET: Retrieve data or resources from Salesforce. | |
// Method to asynchronously retrieve contacts from an external service | |
@future(callout=true) | |
public static void getContacts() { | |
// Instantiate HTTP request and response objects | |
HttpRequest req = new HttpRequest(); | |
HttpResponse response = new HttpResponse(); | |
try { | |
// Set up HTTP request parameters | |
// SourceOrgNamedCredential is your SourceORG Named Credential | |
req.setEndpoint('callout:SourceOrgNamedCredential/services/apexrest/Contact/'); | |
req.setHeader('Content-Type', 'application/json; charset=UTF-8'); | |
req.setHeader('Accept', 'application/json'); | |
req.setMethod('GET'); | |
// Send HTTP request | |
Http http = new Http(); | |
response = http.send(req); | |
// Check if response is successful | |
if (response.getStatusCode() == 200) { | |
// Log successful retrieval of contacts | |
System.debug('Contacts successfully retrieved.'); | |
System.debug('Response Body: ' + response.getBody()); | |
} else { | |
// Log failure to retrieve contacts | |
System.debug('Failed to retrieve contacts. Status code: ' + response.getStatusCode()); | |
System.debug('Response Body: ' + response.getBody()); | |
} | |
} catch (Exception e) { | |
// Log any exceptions that occur during the process | |
System.debug('Exception occurred while retrieving contacts: ' + e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment