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
OdedHarnivOdedHarniv 

Updating records from REST API

Hello everyone

 

I'm using JAVA to extract text from MS docs and update a text filed in my force.com 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;
		try{
			
			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);
			
			httpRequest.setPayload(update.toString().getBytes());
			
			HTTPResponse response = urlFetchService.fetch(httpRequest);
			log.severe("HTTP code:"+response.getResponseCode());
		}
		catch(JSONException e){
		    log.severe("updateCVtxt JSONException:"+ e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e){
		    log.severe("updateCVtxt Exception:"+ e.getMessage());
	    	e.printStackTrace();
	    }
	}

 

 

I have two questions:

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

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

 

Thanks a lot

 

Oded

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

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

All Answers

SuperfellSuperfell

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

OdedHarnivOdedHarniv

Hi simon

 

I get status code 200

 

Thanks

 

Oded

SuperfellSuperfell

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.

OdedHarnivOdedHarniv

I assumed that concatenating the PATCH_METHOD string does the trick.

 

I took the update example here: http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_REST_API and modified it a little. Maybe I did something wrong and the PATCH is not really what is being sent.

 

Any advice?

 

SuperfellSuperfell

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

This was selected as the best answer
OdedHarnivOdedHarniv

Thank you for the insight. 

 

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

Now it works.

 

May thanks