Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Update a Record
You use the sObject Rows resource to update records. Provide the updated record
information in your request data and use the PATCH method of the resource with a
specific record ID to update that record. Records in a single file must be of the same
object type.
In the following example, the Billing City within an Account is updated. The updated record information is provided in patchaccount.json.
Example for updating an Account object
1curl https://MyDomainName.my.salesforce.com/services/data/v67.0/sobjects/Account/001D000000INjVe -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @patchaccount.json -X PATCHExample request body patchaccount.json file for updating fields in an Account object
1{
2 "BillingCity" : "San Francisco"
3}Example response body for updating fields in an Account object
none returned
Error response
The following example uses Java and HttpClient to update a record using REST API. Note
that there is no PatchMethod in HttpClient, so PostMethod is overridden to return
“PATCH” as its method name. This example assumes the resource URL has been
passed in and contains the object name and record
ID.
If
you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP
method name, you can send a POST request and provide an override to the HTTP method via
the query string parameter _HttpMethod. In the
PATCH example, you can replace the PostMethod line with one that doesn't use
override:
1public static void patch(String url, String sid) throws IOException {
2 PostMethod m = new PostMethod(url) {
3 @Override public String getName() { return "PATCH"; }
4 };
5
6 m.setRequestHeader("Authorization", "OAuth " + sid);
7
8 Map<String, Object> accUpdate = new HashMap<String, Object>();
9 accUpdate.put("Name", "Patch test");
10 ObjectMapper mapper = new ObjectMapper();
11 m.setRequestEntity(new StringRequestEntity(mapper.writeValueAsString(accUpdate), "application/json", "UTF-8"));
12
13 HttpClient c = new HttpClient();
14 int sc = c.executeMethod(m);
15 System.out.println("PATCH call returned a status code of " + sc);
16 if (sc > 299) {
17 // deserialize the returned error message
18 List<ApiError> errors = mapper.readValue(m.getResponseBodyAsStream(), new TypeReference<List<ApiError>>() {} );
19 for (ApiError e : errors)
20 System.out.println(e.errorCode + " " + e.message);
21 }
22}
23
24private static class ApiError {
25 public String errorCode;
26 public String message;
27 public String [] fields;
28}1PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH");