-
-
Save TheShubhamVsnv/d16b08fce4c902aef53e37b0a043a43b 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
//PUT: Update existing data or resources in Salesforce. | |
@future(callout=true) | |
public static void putContact() { | |
HttpRequest req = new HttpRequest(); | |
// Use a more meaningful endpoint URL | |
req.setEndpoint('callout:SourceOrgNamedCredential/services/apexrest/Contact/003F900001gMifVIAS'); | |
req.setHeader('Content-Type', 'application/json'); | |
req.setHeader('Accept', 'application/json'); | |
// Use a map to represent the request body and serialize it | |
Map<String, String> requestBodyMap = new Map<String, String>{ | |
'contactFirstName' => 'Steven', | |
'contactLastName' => 'Foster' | |
}; | |
String requestBody = JSON.serialize(requestBodyMap); | |
req.setBody(requestBody); | |
req.setMethod('PUT'); | |
Http http = new Http(); | |
HttpResponse response = http.send(req); | |
// Error handling | |
if (response.getStatusCode() >= 200 && response.getStatusCode() < 300) { | |
system.debug('Contact updated successfully'); | |
system.debug('Response body: ' + response.getBody()); | |
} else { | |
system.debug('Error updating contact. Status code: ' + response.getStatusCode()); | |
system.debug('Response body: ' + response.getBody()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment