-
-
Save TheShubhamVsnv/35b66720065650227cfe3ba466bca732 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
//PATCH: Partially update existing data or resources in Salesforce. | |
@future(callout=true) | |
public static void patchContact() { | |
HttpRequest req = new HttpRequest(); | |
// SourceOrgNamedCredential is your SourceORG Named Credential | |
// 003F900001gMifVIAS is the Id of targetORG contact which we are updateing | |
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' => 'Updated Steven', | |
'contactLastName' => 'Updated Foster' | |
}; | |
String requestBody = JSON.serialize(requestBodyMap); | |
req.setBody(requestBody); | |
req.setMethod('PATCH'); | |
Http http = new Http(); | |
HttpResponse response = http.send(req); | |
// Error handling | |
if (response.getStatusCode() == 200) { | |
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