How To Get Fields Definition of sObject and Get Specific Field ID Using REST API
June 05, 2023
In this blog we will discuss how to get fields definition and field id of an sobject using rest api through postman.
After completing this blog, you’ll be able to:
- How to get fields definition of an object
- How to get field Id of an object
- How to get sObject definition
- How to get picklist values of fields
How to get fields definition of an object
We can get a field definition of an object using Rest Api. you need to call that api in the postman.
Step 1: Get Access Token in Postman like this:
To get Access Token you need to create the first Connected App in Salesforce ORG then you can find client Id and client secret there.
1.1 Paste the below URL in postman set method GET
1.2 Click on Send Button
URL: https://login.salesforce.com/services/oauth2/token?client_id={Your_Client_ID}&username={UserName}&password={password}&grant_type=password&client_secret={your_client_secret}
Here:
- Client_id = Your client Id
- Username = Your Salesforce org username
- Password = Your Salesforce org password
- grant_type = password
- Client_secret = Your Client Secret
Step 2: Make API call to get Fields Definition of an object in postman
URL:
{{_endpoint}}/services/data/v{{version}}/query/?q=SELECT DeveloperName,QualifiedApiName,NewUrl,(SELECT Id, DeveloperName, DurableId FROM Fields) FROM EntityDefinition WHERE QualifiedApiName = ‘Lead’
Here:
- {{_endpoint}} = your salesforce org base url
- {{version}} = your salesforce org version
- QualifiedApiName = sobject name which you want to get fields definition
Step 3: Make API call to Get Custom Field Id of an object
URL:
{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=select+Id+FROM+CustomField+WHERE+DeveloperName+=+{{Custom Field API Name}}+AND+TableEnumOrId=’Lead’
Here:
- {{_endpoint}} = your salesforce org base url
- {{version}} = your salesforce org version
- DeveloperName = custom field name without “__c”
- TableEnumOrId = sObject Name
Step 4: Make API call to get sObject definition
URL:
{{_endpoint}}/services/data/v{{version}}/sobjects/{{sobjectsName}}/describe
Here:
- {{_endpoint}} = your salesforce org base url
- {{version}} = your salesforce org version
- {{sobjectsName}} = replace the with your salesforce sObject name
Step 5: Make API call to get picklist values of fields
URL:
{{_endpoint}}/services/data/v{{version}}/ui-api/object-info/{{sobjectsName}}/picklist-values/{{record_type_Id}}
Here:
- {{_endpoint}} = your salesforce org base url
- {{version}} = your salesforce org version
- {{sobjectsName}} = replace with your salesforce sObject name
- {{record_type_Id}} = replace with your sObject's record type Id
I hope this blog helped you!