You need to sign in to do that
Don't have an account?
Yoram Melnik
Error in Rest tooling api
Hi,
I am trying to update a metadata field and get an error as seen below.
Will appreciate any help!
Thx
Yoram
Below are 2 REST queries that I am performing.
1. The first on gets all the complianceGroup fields form fieldDefinition for a certain object.
From the query I get the complianceGroup Id and url.
2. The second one tires to patch a new value to the url and id received in the first query.
First select query:
https://um6.salesforce.com/services/data/v49.0/tooling/query/?q=Select+Id,+complianceGroup+From+FieldDefinition+WHERE+EntityDefinitionId+in('Account')
The result is:
Url: /services/data/v49.0/tooling/sobjects/FieldDefinition/Account.Fax
Id: 000000000000000AAA
Second select query:
Header: PATCH https://um6.salesforce.com/services/data/v49.0/tooling/sobjects/FieldDefinition/Account.Fax/000000000000000AAA HTTP/1.1
The result for this query is the following error:
[ {
"errorCode" : "NOT_FOUND",
"message" : "The requested resource does not exist"
} ]
This is the java code for the seocnd select query:
private void setComplianceGroupValue(String complianceUrl, String id, ArrayList<String> categories) throws ParseException, IOException, ResponseNotOKException {
for (Iterator iterator = categories.iterator(); iterator.hasNext();) {
String currentCagtegory = (String) iterator.next();
//Set up the HTTP objects needed to make the request.
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPatch patch = new HttpPatch(complianceUrl + "/" + id);
Header oauthHeader = new BasicHeader("Authorization", "OAuth " + loginAccessToken);
Header prettyPrintHeader = new BasicHeader("X-PrettyPrint", "1");
//Header xss = new BasicHeader(("X-XSS-Protection: 1; mode=block"), uri);
patch.addHeader(oauthHeader);
patch.addHeader(prettyPrintHeader);
//patch.addHeader(xss);
//patch.setHeader("Content-type", "application/json");
JSONObject jasonCategory = new JSONObject();
jasonCategory.put("id", id);
jasonCategory.put("ComplianceGroup", currentCagtegory);
StringEntity body = new StringEntity(jasonCategory.toString());
body.setContentType ("application/json");
//body.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
patch.setEntity(body);
// Make the request.
HttpResponse response = httpClient.execute(patch);
String getResult = EntityUtils.toString(response.getEntity());
// if respone is not 200 (ok) than an exception is thrown
proccessHttpResponse(response, complianceUrl+ "/" + id);
LoggerSingelton.getInstance().getLogger().info("postAttributes result: {}. {}", getResult ,SalesforceRestService.class.getSimpleName());
}
}
I am trying to update a metadata field and get an error as seen below.
Will appreciate any help!
Thx
Yoram
Below are 2 REST queries that I am performing.
1. The first on gets all the complianceGroup fields form fieldDefinition for a certain object.
From the query I get the complianceGroup Id and url.
2. The second one tires to patch a new value to the url and id received in the first query.
First select query:
https://um6.salesforce.com/services/data/v49.0/tooling/query/?q=Select+Id,+complianceGroup+From+FieldDefinition+WHERE+EntityDefinitionId+in('Account')
The result is:
Url: /services/data/v49.0/tooling/sobjects/FieldDefinition/Account.Fax
Id: 000000000000000AAA
Second select query:
Header: PATCH https://um6.salesforce.com/services/data/v49.0/tooling/sobjects/FieldDefinition/Account.Fax/000000000000000AAA HTTP/1.1
The result for this query is the following error:
[ {
"errorCode" : "NOT_FOUND",
"message" : "The requested resource does not exist"
} ]
This is the java code for the seocnd select query:
private void setComplianceGroupValue(String complianceUrl, String id, ArrayList<String> categories) throws ParseException, IOException, ResponseNotOKException {
for (Iterator iterator = categories.iterator(); iterator.hasNext();) {
String currentCagtegory = (String) iterator.next();
//Set up the HTTP objects needed to make the request.
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPatch patch = new HttpPatch(complianceUrl + "/" + id);
Header oauthHeader = new BasicHeader("Authorization", "OAuth " + loginAccessToken);
Header prettyPrintHeader = new BasicHeader("X-PrettyPrint", "1");
//Header xss = new BasicHeader(("X-XSS-Protection: 1; mode=block"), uri);
patch.addHeader(oauthHeader);
patch.addHeader(prettyPrintHeader);
//patch.addHeader(xss);
//patch.setHeader("Content-type", "application/json");
JSONObject jasonCategory = new JSONObject();
jasonCategory.put("id", id);
jasonCategory.put("ComplianceGroup", currentCagtegory);
StringEntity body = new StringEntity(jasonCategory.toString());
body.setContentType ("application/json");
//body.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
patch.setEntity(body);
// Make the request.
HttpResponse response = httpClient.execute(patch);
String getResult = EntityUtils.toString(response.getEntity());
// if respone is not 200 (ok) than an exception is thrown
proccessHttpResponse(response, complianceUrl+ "/" + id);
LoggerSingelton.getInstance().getLogger().info("postAttributes result: {}. {}", getResult ,SalesforceRestService.class.getSimpleName());
}
}
https://um6.salesforce.com/services/data/v49.0/tooling/sobjects/FieldDefinition/Account.Fax
(Without the extra /000000000000000AAA)
000000000000000AAA is a weird FieldDefinition ID as all fields kinda have it, just the DurableID value needs to be used (Account.Fax)