Skip to content

Instantly share code, notes, and snippets.

@TheShubhamVsnv
Created March 7, 2024 07:33
Show Gist options
  • Save TheShubhamVsnv/1e4f0c5cc1301cf8a26c6fbc9b9a9d3c to your computer and use it in GitHub Desktop.
Save TheShubhamVsnv/1e4f0c5cc1301cf8a26c6fbc9b9a9d3c to your computer and use it in GitHub Desktop.
@HttpPatch
global static String patchContact(String contactFirstName, String contactLastName) {
RestRequest req = RestContext.request;
String contactId = req.requestURI.substring(req.requestURI.lastindexof('/') + 1);
try {
// Fetch the contact record
Contact con = [SELECT Id, FirstName, LastName FROM Contact WHERE Id = :contactId LIMIT 1];
// Update contact fields based on provided parameters
if (contactFirstName != null) {
con.FirstName = contactFirstName;
}
if (contactLastName != null) {
con.LastName = contactLastName;
}
// Perform the update
update con;
// Return the updated contact record
return JSON.serialize(con);
} catch (Exception e) {
return 'Error updating contact: ' + e.getMessage();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment