function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Updating records from REST API

Hello everyone


I'm using JAVA to extract text from MS docs and update a text filed in my Org.

The JAVA code is hosted on google application engine.

The code works OK but the update doesn't change anything in my Org.


This is my code:


	public void updateCVtxt(String candidateID, String cvTxt){

		log.severe("updateCVtxt for:" + candidateID);		
                public static final String PATCH_METHOD = "?_HttpMethod=PATCH";

		String restURI = instanceURL + "/services/data/v" + sfdcApiVersion +
						 "/sobjects/SocialRecruite__Candidate__c/" + candidateID;
			URL url = new URL(restURI + PATCH_METHOD);
			URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
			HTTPRequest httpRequest = new HTTPRequest(url);

			httpRequest.setHeader(new HTTPHeader("Authorization", "OAuth "+ accessToken));
			httpRequest.setHeader(new HTTPHeader("Content-Type", "application/json"));
			JSONObject update = new JSONObject();
			update.put("SocialRecruite__Resume_CV__c", cvTxt);
			HTTPResponse response = urlFetchService.fetch(httpRequest);
			log.severe("HTTP code:"+response.getResponseCode());
		catch(JSONException e){
		    log.severe("updateCVtxt JSONException:"+ e.getMessage());
		catch(Exception e){
		    log.severe("updateCVtxt Exception:"+ e.getMessage());



I have two questions:

1) Where can I see the log of what happens on the side when it gets this request?

2) Maybe I'm doing something wrong.  Is my code correct?


Thanks a lot





Best Answer chosen by Admin (Salesforce Developers) 

The _HttpMethod override only works if the real request method is POST.

All Answers


What status code & response body do you get as a result of the PATCH request?


Hi simon


I get status code 200






You wouldn't get a 200 from a PATCH request, sounds like you might be doing a GET, i see nothing that sets the http method to POST in your code.


I assumed that concatenating the PATCH_METHOD string does the trick.


I took the update example here: and modified it a little. Maybe I did something wrong and the PATCH is not really what is being sent.


Any advice?



The _HttpMethod override only works if the real request method is POST.

This was selected as the best answer

Thank you for the insight. 


I thought the Patch replaces the Post but I guess it is in addition.

Now it works.


May thanks