I am producing a query in Java which gets two fields from an SObject collection in Salesforce, and returns them over a REST call.


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);

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!

1 Answer 1


Please check your endpoint URL:


Version can be different depends on your salesforce org.

  • This worked. I definitely tried it before and it didn't! Maybe I forgot the leading slash or the /data/ part. Thanks!
    – dahui
    Mar 27, 2018 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .