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
MktdevMktdev 

Rest API - updating Record

Hi,

 

I am trying to update record. I tried both PATCH and POST as instructed in document but its not working.

 

when used Patch then I get "Invalid HTTP method: PATCH"

when I used POST then I get 

"message" : "HTTP Method 'POST' not allowed. Allowed are HEAD,GET,PATCH,DELETE",
  "errorCode" : "METHOD_NOT_ALLOWED"

 

Can anyone help? Below the code

 

 

HttpRequest req = new HttpRequest(); 
req.setEndpoint('https://ap1.salesforce.com'+'/services/data/v26.0/sobjects/Contact/0039000000Jzxts');
  req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId()); 
  req.setHeader('X-PrettyPrint', 'true');
  req.setHeader('Content-Type','application/json');
  req.setBody('{"FirstName":"Mktg"}');
  req.setMethod('PATCH');
    
    
   system.debug('URL---'+UserInfo.getSessionId());
 
   Http http = new Http();
       HTTPResponse res = http.send(req);

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MktdevMktdev

Somehow Salesforce is not allowing to do POST or PATCH within Salesforce. Later I used other Rest Client tool I was able to test it.