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

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:

  1. Client_id = Your client Id
  2. Username = Your Salesforce org username 
  3. Password = Your Salesforce org password
  4. grant_type = password
  5. 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:

  1. {{_endpoint}} = your salesforce org base url
  2. {{version}} = your salesforce org version
  3. 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:

  1. {{_endpoint}} = your salesforce org base url
  2. {{version}} = your salesforce org version
  3. DeveloperName = custom field name without “__c”
  4. TableEnumOrId = sObject Name

 

 

Step 4: Make API call to get sObject definition

URL:

{{_endpoint}}/services/data/v{{version}}/sobjects/{{sobjectsName}}/describe

Here:

  1. {{_endpoint}} = your salesforce org base url
  2. {{version}} = your salesforce org version
  3. {{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:

  1. {{_endpoint}} = your salesforce org base url
  2. {{version}} = your salesforce org version
  3. {{sobjectsName}} = replace with your salesforce sObject name
  4. {{record_type_Id}} = replace with your sObject's record type Id

 

 

I hope this blog helped you!