Implementing Salesforce Tooling API Techniques

Nov 23, 2023


 

 

After completing this unit, you will able to:

1.  Introduction

2.  What is Tooling API ?

3.  Authentication

4.  Create a custom field on sobject

5.  Update custom field on sobject

6.  Create Record Type for Standard Object

7.  Create Record Type for Custom Object

8.  Update Record Type for Standard Object

9.  Update Record Type for Custom object

10. Get all the Page Layout Name

 

 

1.  Introduction

Welcome to the world of the Tooling API – where efficiency meets innovation, and every line of code becomes a pathway to enhanced success.

In this Salesforce blog, where we embark on a journey into the heart of Salesforce development, armed with a powerful ally – the Tooling API. In the dynamic realm of application development, efficiency, and precision are paramount, and the Tooling API stands as the beacon guiding developers and administrators toward streamlined workflows and enhanced capabilities.

The Salesforce Tooling API is not just an interface; it's a dynamic toolkit designed to empower developers with programmatic access to a treasure trove of metadata, code, and development-related insights. As we delve into this RESTful web service, we'll uncover its multifaceted capabilities and explore how it transforms the development lifecycle within the Salesforce ecosystem.

Our blog will be your companion as we journey through the fundamental features of the Tooling API. Whether you're a seasoned developer, an aspiring administrator, or someone keen on exploring the depths of Salesforce capabilities, our blog is your gateway to unlocking the power of precision in Salesforce development.

 

2.  What is Tooling API ?

The Salesforce Tooling API stands as a dynamic cornerstone in the toolkit of developers and administrators, offering a robust and versatile set of capabilities to streamline the development lifecycle within the Salesforce ecosystem. Tooling API simplifies the interaction with Salesforce metadata, allowing developers to seamlessly retrieve information about Apex classes, triggers, Visualforce pages, and a myriad of other components that constitute the building blocks of a Salesforce application. This programmatic access not only facilitates code analysis but also supports crucial tasks such as debugging, testing, and deployment.

The Tooling API is a valuable tool for developers working on the Salesforce platform, providing a programmatic interface for tasks related to development, testing, and debugging. It enhances the efficiency of development processes and supports automation in various aspects of Salesforce application development.

 

3.  Authentication

Before diving into Tooling API calls, it's crucial to understand the authentication process. Salesforce uses OAuth 2.0 for authentication, ensuring secure access to your org's metadata. Developers need to obtain a valid access token through the OAuth flow to make authorized requests to the Tooling API.

Get the access token in postman using this link: Get Access Token in Postman

 

4.  Create a custom field on sobject

Request Type: POST

URL: baseUrl/services/data/v56.0/tooling/sobjects/CustomField/

Request Body:

{

  "Metadata": {
    "type": "Text",
    "description": "This is test description for New Text Field.",
    "inlineHelpText": "Test Custom Object New Text Field",
    "label": "New Text Field",
    "length": 255,
    "required": false
  },
  "FullName": "Test_Custom_Object__c.New_Text_Field__c"
}

 

 

 Response:

 

 


5.  Update custom field on sobject


Request Type: PATCH

URL: baseUrl/services/data/v58.0/tooling/sobjects/CustomField/:CustomFieldId

(Make sure you have replaced :CustomFieldId with the your salesforce object's custom field Id)

Request Body:

{

  "Metadata": {
    "type": "Text",
    "description": "This is test description with updated value.",
    "inlineHelpText": "This is test inline help text  with updated value.",
    "label": "New Text Field with Updated Label",
    "length": 50,
    "required": false
  },
  "FullName": "Test_Custom_Object__c.New_Text_Field__c"
}

 

 

 

 Response:

If the Status Code is 204 No Content, this means the field is successfully updated.

 

 

 

6.  Create Record Type for Standard Object


Request Type: POST

URL: baseUrl/services/data/v58.0/tooling/sobjects/RecordType

Request Body:

{
  "Metadata": {
    "active": true,
    "label": "New Record Type",
    "description":"This is test description.",
    "businessProcess":"Test Sales Process"
  },
  "FullName": "Opportunity.NewRecordType"
}
 
(Make sure you created a Sales Process from the setup for the newly opportunity record type and then replace the name of Sales Process in the businessProcess node.)

 

 

 Response:

 

 

 

7.  Create Record Type for Custom Object


Request Type: POST

URL: baseUrl/services/data/v58.0/tooling/sobjects/RecordType

Request Body:

{
  "Metadata": {
    "active": true,
    "label": "New Record Type",
    "description":"This is test description."
  },
  "FullName": "Test_Custom_Object__c.NewRecordType"
}

 

 

 Response:

 

 

 

8.  Update Record Type for Standard Object


Request Type: PATCH

URL: baseUrl/services/data/v58.0/tooling/sobjects/RecordType/:RecordTypeId

(Make sure you have replaced :RecordTypeId with the your record type Id)

Request Body:

{
  "Metadata": {
    "active": true,
    "label": "New Record Type with Updated Label",
    "description":"This is test description with updated value.",
    "businessProcess":"Test Sales Process"
  },
  "FullName": "Opportunity.NewRecordType"
}

 

 

 

 Response:

If the Status Code is 204 No Content, this means the record type is successfully updated.

 

 

 

9.  Update Record Type for Custom object


Request Type: PATCH

URL: baseUrl/services/data/v58.0/tooling/sobjects/RecordType/:RecordTypeId

(Make sure you have replaced :RecordTypeId with the your record type Id)

Request Body:

{
  "Metadata": {
    "active": true,
    "label": "New Record Type with Updated Label",
    "description":"This is test description with updated value."
  },
  "FullName": "Test_Custom_Object__c.NewRecordType"
}

 

 

 

 Response:

If the Status Code is 204 No Content, this means the record type is successfully updated.

 

 

 

10. Get All Page Layout Name


Request Type: GET

URL: baseUrl/services/data/v33.0/tooling/query/?q=Select+id,name,createdDate,fullName+from+Layout+where+EntityDefinitionId=:sObjectId

(Make sure you have replaced :sObjectId with the salesforce object's Id)

 

 

 Response:

{
    "size": 2,
    "totalSize": 2,
    "done": true,
    "queryLocator": null,
    "entityTypeName": "Layout",
    "records": [
        {
            "attributes": {
                "type": "Layout",
                "url": "/services/data/v33.0/tooling/sobjects/Layout/00h5i00000BriU5AAJ"
            },
            "Id": "00h5i00000BriU5AAJ",
            "Name": "test",
            "CreatedDate": "2023-11-17T12:40:13.000+0000",
            "FullName": "Test_Custom_Object__c-Test Layout"
        },
        {
            "attributes": {
                "type": "Layout",
                "url": "/services/data/v33.0/tooling/sobjects/Layout/00h5i00000IrVXEAA3"
            },
            "Id": "00h5i00000IrVXEAA3",
            "Name": "Test Custom Object Layout",
            "CreatedDate": "2023-08-28T06:17:09.000+0000",
            "FullName": "Test_Custom_Object__c-Test Custom Object Layout"
        }
    ]
}
 

 

 

I hope this blog helped you!