Salesforce Bulk API: Create The Job

Looking for Salesforce Training & HandsOn Projects?

Trailblazer Profile | LinkedIn | Salesforce Blog | Facebook | Youtube Channel | WhatsApp Community 

What is Salesforce Bulk API?

Salesforce Bulk API is a REST-based API that allows you to asynchronously insert, upsert, query, or delete large datasets in your Salesforce org. It is a powerful tool for loading and updating large amounts of data in Salesforce, and it can be used to automate many data-intensive tasks.
Salesforce Bulk API offers a comprehensive suite of API calls for performing various data operations on large datasets. These API calls encompass the entire data management lifecycle, from creating jobs to processing data and retrieving results.

Here's an overview of the key API calls involved in Salesforce Bulk API:

  • Create Job: Initiates a new bulk operation by creating a job that defines the operation's parameters. This includes specifying the operation type (insert, update, upsert, or delete), the object to be processed, and the data format.
  • Upload Job Data: Uploads the bulk data to be processed to Salesforce. This can be done in chunks to handle large datasets.
  • Close Job: Signals the completion of data upload and finalizes the job for processing.
  • Get Job Information: Retrieves detailed information about a specific bulk job, including its status, progress, and any errors encountered.
  • Get Job Results: Retrieves the results of a completed bulk operation, providing insights into the success or failure of individual data records.
  • Get Job Batch Information: Retrieves detailed information about a specific batch within a bulk job, providing granular insights into the processing of individual data chunks.
  • Get Job Batch Results: Retrieves the results of a processed batch, providing detailed information about the success or failure of individual data records within that batch.
  • Delete Job: Removes a completed bulk job and its associated data from Salesforce.
  • Get Async Request Limits: Retrieves the current limits for asynchronous requests, including the maximum number of concurrent jobs and batches allowed.
  • Get Async Result Limits: Retrieves the current limits for asynchronous results, including the maximum size of individual result files.

When should we use Salesforce Bulk API?

You should use Salesforce Bulk API when you need to process large amounts of data in Salesforce. Any data operation that includes more than 2000 records is a good candidate for Bulk API. For example, you could use Bulk API to:

  • Import a large list of leads into Salesforce
  • Updating the prices of thousands of products
  • Delete old records from your Salesforce org
  • Removing duplicate records from a database
  • Merging two Salesforce orgs

Why should we use Salesforce Bulk API?

The Bulk API has a number of advantages over other methods of working with large datasets in Salesforce, including:

  • It is asynchronous, so you can submit a batch of records and continue working with Salesforce while the batch is being processed
  • It is designed to handle large datasets, so you can process thousands or even millions of records at a time
  • It is efficient, so it can process large datasets quickly
  • It is secure, so your data is protected

In this article, we will explore the "Create Job" API Call using Postman (API Client) in a step-by-step process as follows:

Step-1: We already have a custom object called "Invoice" that we will be using across different API Calls under Bulk API implementations

Step-2: Launch Postman & create a new API request as shown. Let's call it "Create a Job"

Step-3: This is going to be a POST Request. Select "POST" as the Http Protocol

Step-4: Build the API End Point using the following convention-

<Salesforce Org Host Header>/services/async/<api version>/job

Step-5: Click on the "Headers" section to add the required header prams to the request

Step-6: "Content-Type" & "X-SFDC-Session" are minimum required headers with Bulk API

Note: The X-SFDC-Session header is a custom HTTP header used in Salesforce Bulk API requests to authenticate the user and identify the active session for that user. It contains a session ID, which is a unique identifier generated by Salesforce when a user logs in. The session ID is used to verify the user's identity and ensure that they have the necessary permissions to perform the requested bulk operation.

Step-7: Show values to be entered for the header param. Make sure to enter the correct session ID in "X-SFDC-Session" as per your login step. You can check the post on Salesforce REST API: The Login Request (Authentication Step)

Step-8: Click on the "Body" section to add the content to the request body as shown. Here is the explanation of each of the attributes constituting the XML request envelope-

  • Operation
    • The operation property specifies the type of bulk operation to be performed. Valid values are:
      • insert: Insert new records into the specified Salesforce object.
      • update: Update existing records in the specified Salesforce object.
      • upsert: Upsert records into the specified Salesforce object. This means that if a record with the same external ID already exists, it will be updated; otherwise, a new record will be inserted.
      • delete: Delete records from the specified Salesforce object.
  • Object
    • The object property specifies the Salesforce object on which the bulk operation will be performed. This must be the name of a Salesforce standard object or custom object.
  • External ID
    • The externalIdFieldName property (optional) specifies the external ID field in the object being updated. This property is only needed for upsert operations. Field values must also exist in CSV job data.
  • Content Type
    • The contentType property (optional) specifies the content type for the job. The only valid value is CSV.
  • Column Delimiter
    • The columnDelimiter property (optional) specifies the column delimiter used for CSV job data. The default value is COMMA. Valid values are:
      • BACKQUOTE: Backquote character (``)
      • CARET: Caret character (^)
      • COMMA: Comma character (,)
      • PIPE: Pipe character (|)
      • SEMICOLON: Semicolon character (;)
      • TAB: Tab character
  • Line Ending
    • The lineEnding property (optional) specifies the line ending used for CSV job data, marking the end of a data row. The default is LF. Valid values are:
      • LF: Linefeed character
      • CRLF: Carriage return character followed by a linefeed character
  • Concurrency Mode
    • The concurrencyMode property (optional) specifies the desired concurrency mode for processing the job. The default value is SERIAL. Valid values are:
      • SERIAL: Processes the job sequentially, one batch at a time.
      • PARALLEL: Processes the job in parallel, using multiple batches to improve performance.
  • Job Data
    • The jobData property (optional) contains the bulk data to be processed. This data can be provided directly in the request body or uploaded separately using the Upload Job Data API.

Step-9: Based on the knowledge on this topic, we can build the XML request envelope as shown

Step-10: Finally we can click on "Send" to submit the API Request

Step-11: If everything goes well, we would be getting "Status 201 Created" as the response code. Also would be getting the response object as shown. Notice, how the Job ID, Operation, Object & other key information are shown

Step-12: It is important to take note of the job state "state" attribute, and we can see it as "Open" that means the job is ready to add a batch of data to be processed

And this is it for this demo.

Conclusion

In conclusion, the Salesforce Bulk API Create Job API stands as a cornerstone of data management within Salesforce organizations. Its ability to initiate, manage, and track bulk operations makes it an indispensable tool for administrators and developers alike. By leveraging the Create Job API, users can harness the power of Bulk API to optimize data processing workflows, enhance data integrity, and streamline data-driven decision-making.


Comments