I've just started to use the rest Salesforce API to query Opportunity data. I'm trying via the API to get the Opportunity fields as well as their type. For now, I've been using an API call on a random opportunity ('/services/data/v43.0/sobjects/Opportunity/0062X000011F5rTQAS') and looked at the object keys directly, but I'm hitting a problem getting the type of each field because some have no value and thus have no type (because they are None when queried). Is there an API route I could use to query Opportunity metadata (ie fields and their type) ?
2 Answers
Sure, you're almost there, but instead of record Id, you should reference sObject describe:
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_describe.htm
https://yourInstance.salesforce.com/services/data/v43.0/sobjects/Account/describe/ -H "Authorization: Bearer token"
You can field fields API names, labels and types in fields section.
-
Thanks a lot I couldn't find it myself in all the documentation available, have a great day Mariia :) Jul 20, 2020 at 11:41
You can use the ui-api to retrieve both a record and general object information at once. That is found in the Get Record Data and Object Metadata resource, accessed by /ui-api/record-ui/{recordId}
.