Reputation: 1915
What is meaning/significance of +1 in below Salesforce REST APEX Code
@HttpPatch
global static ID updateCaseFields() {
RestRequest request = RestContext.request;
String caseId = request.requestURI.substring(
request.requestURI.lastIndexOf('/')+1);
Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];
// Deserialize the JSON string into name-value pairs
Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(request.requestbody.tostring());
// Iterate through each parameter field and value
for(String fieldName : params.keySet()) {
// Set the field and value on the Case sObject
thisCase.put(fieldName, params.get(fieldName));
}
update thisCase;
return thisCase.Id;
}
}
Upvotes: 0
Views: 1621
Reputation: 26
That +1 is within the substring()
function, so it is adding one to the last index of "/" in the request uri in order to grab the case ID.
ex) The URI typically looks something like this:
https://<instance>.salesforce.com/Case/<some_case_id>
The + 1 allows the substring function to look at one place past the last forward slash "/" to grab the case id at the end of the uri.
Upvotes: 1