-
-
Save TheShubhamVsnv/9bf6fdaf4b1ff71da3c39b27fa38ab9a 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
@HttpPut | |
global static string putContact(String contactFirstName, String contactLastName) { | |
RestRequest req = RestContext.request; | |
// Use more meaningful variable names | |
String contactId = req.requestURI.substring(req.requestURI.lastindexof('/') + 1); | |
// Add error handling for query | |
Contact con; | |
try { | |
con = [SELECT Id FROM Contact WHERE Id = :contactId LIMIT 1]; | |
} catch (Exception e) { | |
return 'Error: ' + e.getMessage(); | |
} | |
// Update contact fields directly without querying | |
con.FirstName = contactFirstName; | |
con.LastName = contactLastName; | |
update con; | |
// Return a JSON response instead of a concatenated string | |
return JSON.serialize(con); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment