API Testing with Katalon and Salesforce

API testing with Katalon and Salesforce is a critical component for ensuring the reliability and performance of Salesforce applications. By leveraging Katalon’s comprehensive testing capabilities alongside Salesforce’s robust API ecosystem, teams can create powerful automated tests that verify the functionality and security of their Salesforce integrations and workflows.

This introduction guides you through setting up API testing within Salesforce, highlighting the importance of incorporating API testing in your test data management strategy. Understanding how to create and manage APIs in Salesforce’s Object Manager is the first step toward achieving a seamless testing process. API testing plays a crucial role in identifying discrepancies and vulnerabilities early in the development cycle, making it an indispensable part of modern software development practices.

With the right setup, teams can automate their testing processes, reduce manual errors, and ensure their Salesforce applications meet the highest standards of quality and performance. This overview will demonstrate how to configure API testing in Salesforce using Katalon, and underscore the significance of integrating these tests with test data management to maximize efficiency and effectiveness.


Types of Salesforce APIs

  1. REST API
    The REST API is a simple, lightweight option based on REST principles. It is used for interacting with Salesforce data using standard HTTP methods (GET, POST, PATCH, DELETE).
    Use Case: Retrieving records, creating new records, updating or deleting existing records.

  2. SOAP API
    The SOAP API provides a more complex, XML-based protocol that is ideal for integrating with legacy systems. SOAP is used to work with Salesforce objects and data in real-time.
    Use Case: Integrating with enterprise systems where strict XML-based communication is required.

  3. Bulk API
    The Bulk API is optimized for processing large volumes of data asynchronously. It’s useful for loading or deleting data in bulk.
    Use Case: Importing or exporting thousands or millions of records.

  4. Streaming API
    The Streaming API is used for receiving real-time notifications from Salesforce. This API is ideal for applications that need to monitor changes to Salesforce data and act accordingly.
    Use Case: Event-driven architecture, real-time dashboards.

  5. Metadata API
    The Metadata API allows you to retrieve, deploy, and manage metadata within Salesforce (like Apex classes, custom objects, workflows, etc.).
    Use Case: Migrating configurations between environments.


Example 1: Retrieving Data Using Salesforce REST API

To retrieve data from Salesforce using the REST API, you’ll typically use a GET request. Here’s how you can retrieve records from the Salesforce Account object using Katalon Studio:

Step 1: Set Up OAuth2 Authentication

Before making a request, you’ll need to authenticate and get an access token. Once you have the token:

Step 2: Retrieve Data (GET Request)

  • Endpoint: https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/{AccountId}

Example:

GET https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/001D000000IqhSL
Authorization: Bearer {access_token}
  • Katalon Studio Setup:
    1. Create a new RESTful Request in Katalon Studio.
    2. Set the method to GET.
    3. In the URL field, paste your Salesforce endpoint, replacing {AccountId} with an actual Account ID.
    4. Under the Authorization tab, choose Bearer Token and insert the token retrieved from the Salesforce OAuth2 process.
    5. Run the request, and you should retrieve the details of the specified Account.

Response Example (JSON):

{
  "Id": "001D000000IqhSL",
  "Name": "Acme Corporation",
  "Phone": "1234567890",
  "Website": "http://www.acme.com",
  ...
}

Example 2: Posting Data Using Salesforce REST API

To create a new record in Salesforce, you will use a POST request. For this example, let’s create a new Account.

Step 1: Authenticate

Make sure you have your access token ready after completing the OAuth2 flow.

Step 2: Post Data (POST Request)

  • Endpoint: https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/

Example:

POST https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/
Authorization: Bearer {access_token}
Content-Type: application/json

{
  "Name": "New Acme Corporation",
  "Phone": "9876543210",
  "Website": "http://www.newacme.com"
}
  • Katalon Studio Setup:
    1. Create a new RESTful Request in Katalon Studio.
    2. Set the method to POST.
    3. In the URL field, paste your Salesforce endpoint.
    4. Under the Authorization tab, choose Bearer Token and insert the token retrieved from the Salesforce OAuth2 process.
    5. Go to the Body section and select Raw as the body type. Then paste the JSON structure for the new record.
    6. Run the request, and Salesforce will create a new Account record.

Response Example:

{
  "id": "001D000000IqhSL",
  "success": true,
  "errors": []
}

Example 3: Updating Data Using Salesforce REST API

To update an existing record, you’ll use a PATCH request. For this example, we’ll update the Phone number of an existing Account.

  • Endpoint: https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/{AccountId}

Example:

PATCH https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/001D000000IqhSL
Authorization: Bearer {access_token}
Content-Type: application/json

{
  "Phone": "5551234567"
}
  • Katalon Studio Setup:
    1. Set the method to PATCH in your RESTful Request.
    2. In the Body section, update the JSON structure with the fields you want to modify.
    3. Execute the request, and Salesforce will update the Account.

Response Example (Success):

{
  "success": true,
  "errors": []
}

Example 4: Deleting Data Using Salesforce REST API

To delete a record, use a DELETE request. For this example, we’ll delete an existing Account.

  • Endpoint: https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/{AccountId}

Example:

DELETE https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/001D000000IqhSL
Authorization: Bearer {access_token}
  • Katalon Studio Setup:
    1. Set the method to DELETE in your RESTful Request.
    2. Run the request, and the specified Account will be deleted from Salesforce.

Response Example (No Content):

  • A successful deletion returns no content, indicated by a 204 status code.

Example of Bulk API: Loading Data

With Bulk API, you can load large volumes of data asynchronously. Let’s load 1,000 records into the Account object using Bulk API v2.

  • Endpoint: https://yourInstance.salesforce.com/services/data/vXX.X/jobs/ingest

Example Request (POST to Create a Job):

POST https://yourInstance.salesforce.com/services/data/vXX.X/jobs/ingest
Authorization: Bearer {access_token}
Content-Type: application/json

{
  "object": "Account",
  "contentType": "CSV",
  "operation": "insert"
}

Once the job is created, you can upload the CSV file containing the records and monitor the job’s progress.