-
-
Save TheShubhamVsnv/1e4f0c5cc1301cf8a26c6fbc9b9a9d3c 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
@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