+ Start a Discussion
Denise CrosbyDenise Crosby 

rest api update error "the id field should not be specified in the sobject data"

I am trying to update a custom object using REST api like this:

REST method:
POST
 
URI endpoint: 
/services/data/v41.0/sobjects/estimator__c
 
Request header:
Content-Type: application/json; charset=UTF-8
Accept: application/json
 
Request body:
{
  "id" : "a014100000OsY9iAAF",
  "active__c" : "false"

}
 
I get error

INVALID_FIELD
  • message: The Id field should not be specified in the sobject data.
  • errorCode: INVALID_FIELD
Can someone help me understand what format I need to use for an update? I am new to APIs. Many thanks
Best Answer chosen by Denise Crosby
Alain CabonAlain Cabon
Hi Denise,

What apex code are you using? or are you just using the workbench?

REST method: 
PATCH
 
URI endpoint:  
/services/data/v41.0/sobjects/estimator__c/a014100000OsY9iAAF
 
Request header:
Content-Type: application/json; charset=UTF-8
Accept: application/json
 
Request body:
{
  "active__c" : "false"
}

For an update, use: "PATCH" instead of "POST" with the workbench.

You can read this great Aakanksha Singh's post for complete examples:  For editing/updating records through REST API we use the /sobjects/ URI. Please make sure HTTP method is set to PATCH:  https://webkul.com/blog/how-to-run-rest-api-through-workbench-salesforce/

https://trailhead.salesforce.com/en/modules/api_basics/units/api_basics_rest

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_update_fields.htm

All the best
Alain

All Answers

Alain CabonAlain Cabon
Hi Denise,

What apex code are you using? or are you just using the workbench?

REST method: 
PATCH
 
URI endpoint:  
/services/data/v41.0/sobjects/estimator__c/a014100000OsY9iAAF
 
Request header:
Content-Type: application/json; charset=UTF-8
Accept: application/json
 
Request body:
{
  "active__c" : "false"
}

For an update, use: "PATCH" instead of "POST" with the workbench.

You can read this great Aakanksha Singh's post for complete examples:  For editing/updating records through REST API we use the /sobjects/ URI. Please make sure HTTP method is set to PATCH:  https://webkul.com/blog/how-to-run-rest-api-through-workbench-salesforce/

https://trailhead.salesforce.com/en/modules/api_basics/units/api_basics_rest

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_update_fields.htm

All the best
Alain
This was selected as the best answer
Denise CrosbyDenise Crosby
Thank you SO MUCH Alain. You have the BEST answers and explanations! I am using Workbench for this and your solution is working. Many thanks for helping.
Alain CabonAlain Cabon
Now, it all makes sense to you know and I improved my own knowledge (nothing about the update into the api basics rest module of trailhead).. 

1) By the way, for boolean values,  it is just  "active__c" : false (without double-quotation marks). you already type the corrected value yourself for sure as needed and I made my tests without double-quotation marks with a checkbox field (but at the end, I copy/paste your value as active__c could be a string for you).

2) Add Lookup Field Lightning Component:  Marcus Torres and Greg Rewis communicated about this very expected component on the idea below.

<lightning:inputField> with a lookup field in Spring '18.

Marcus Torres and Greg Rewis are both known in France because they gave lectures on Lightning components during the European Lightning Now Tours in 2016 and 2017. 

https://success.salesforce.com/ideaView?id=08730000000Dom1AAC