Skip to main content
Scott VandenElzen a posé une question dans #Ask An Expert
Hi All-

 

I'm trying to use the REST API to do an update to a Case in C#

 

Here is my code.

 

// urec is my class that contains updates for a case to be serialized out

 

SFUpdate urec = new SFUpdate();

 

urec.Rank = 123;

 

urec.Planning_Meeting = true;

 

// notice I'm adding the HttpMethod=Patch query string to simulate a PATCH since the HttpClient doesn't support a PATCH command

 

System.Uri uri = new System.Uri(serviceUrl + rec.url + "?_HttpMethod=PATCH");

 

HttpClient queryClient = new HttpClient();

 

queryClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + oauthToken);

 

HttpResponseMessage response = queryClient.PostAsJsonAsync(uri, urec).Result;

 

--------------

 

When I run this I get the response

 

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

 

{

 

  Sforce-Limit-Info: api-usage=47/5000

 

  Transfer-Encoding: chunked

 

  Date: Sat, 10 May 2014 01:22:12 GMT

 

  Content-Type: application/json; charset=UTF-8

 

}}

 

If I remove the HttpMethod=PATCH query string variable I get this when I run it (it doesn't seem to like POST because it's an update.

 

{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

 

{

 

  Sforce-Limit-Info: api-usage=48/5000

 

  Connection: close

 

  Date: Sat, 10 May 2014 01:24:04 GMT

 

  Allow: HEAD

 

  Allow: GET

 

  Allow: PATCH

 

  Allow: DELETE

 

  Content-Type: application/json; charset=UTF-8

 

}}

 

HELP!

 

Scott
2 réponses
  1. 12 mai 2014, 00:33
    Problem solved!  Rank and Planning_meeting were custom fields inside salesforce.  They need to be Rank__c and Planning_Meeting__c in the class so when it's serialized they have the appropriate name.

     

    Scott