Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateSObject: "The Id field should not be specified in the sobject data" #69

Open
hf-kklein opened this issue Apr 19, 2018 · 1 comment

Comments

@hf-kklein
Copy link
Contributor

Hi,
I'm using the example code to update an object. The object has an id and some properties, just like this:

@JsonIgnoreProperties(ignoreUnknown=true)
public static class MyObject {
	@JsonProperty(value="Id")
	private String id;
	@JsonProperty(value="some_property__c")
	private String some_property__c;

        public String getId() {return id;}
        public void setId(String Id) {this.id = Id;}
        public String getSome_property__c() {return some_property_c;}
        public void setSome_property__c(String some_propery__c) {this.some_property__c = some_property__c;}
	}

When I try to change the property, my program fails:

final String query = "SELECT id, some_property__c FROM sometable";
QueryResult<MyObject> result = api.query(query, MyObject.class);
for (MyObject mo : result.getRecords()) {
	mo.setSome_property__c("some value");
	api.updateSObject("sometable", mo.getId(), mo);
}

The error message of the API with HTTP status code 400 (bad request) ist:

[
	{
		"message": "The Id field should not be specified in the sobject data.",
		"errorCode": "INVALID_FIELD"
	}
]

The Java error is:

INFO com.force.api.http.Http - Bad response code: 400 on request: POST https://myinstance.my.salesforce.com/services/data/v39.0/sobjects/sometable/thealphanumerickey?_HttpMethod=PATCH
Accept: application/json
Content-Type: application/json
Authorization: Bearer ...
{"Id":"thealphanumerickey","some_property__c":"some value"}

And in fact, as soon as I modify the request body, so that it does not contain the id, it works fine.

API version is 39.0

@FabienTaillon
Copy link

We just had the same issue.

As a workaround, we set the id to null before calling the updateSObject and it works fine:
mo.setId(null);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants