I am producing a query in Java which gets two fields from an SObject collection in Salesforce, and returns them over a REST call.
SELECT Id, Name FROM Lead
It is possible for me to manually search for the objects fields in the Salesforce UI, however I would like to do it programatically, so the fields are discovered and then used in the query string. I'd also like to do this over REST, in the same program.
I've seen a few examples how to do this in Java, but I'm not sure how to get the "Schema" object referred to in the example, such as this one.
I'd prefer to be able to do this also over REST with Java, so I can grab the fields, put them in an array of Strings and append them to the query string of my second REST call.
I found out there is a describe REST endpoint for Salesforce, however, when I poll it I get a 404 not found, so may be using the wrong URL.
final URIBuilder builder = new URIBuilder(instanceUrl);
builder.setPath("/v36.0/sobjects/Lead/describe");
final HttpGet get = new HttpGet(builder.build());
get.setHeader("Authorization", "Bearer " + accessToken);
final HttpResponse response = http.execute(get);
final JsonNode results = mapper.readValue(response.getEntity().getContent(), JsonNode.class);
instanceUrl and accessToken are both returned from successfully authenticating to salesforce.
If anyone has knowledge, or an example, of how to get the object field names purely through REST, I'd be grateful!