Salesforce Bulk API: Closing The Job

Looking for Salesforce Training & HandsOn Projects?

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

In Salesforce Bulk API, closing a job signals the completion of batch submission for a particular operation. This important step enables more accurate progress monitoring and prevents further batch additions, ensuring data integrity.

To refresh your memory on fundamental Bulk API concepts, I encourage you to revisit my prior articles on Bulk API: 

Closing a job is typically initiated after all intended batches have been submitted successfully. Once closed, no further batches can be added to the job. Closing a job doesn't immediately halt ongoing processing. Salesforce continues to process any remaining batches. Closed jobs can still be monitored using the Bulk API monitoring page or API calls.

Ways to Close the Bulk API Job

Using Salesforce UI

  • Navigate to Setup > Environments > Jobs > Bulk Data Load Jobs
  • Locate the desired job and click the Close button.


Using Bulk API Call

Here's a breakdown of the code to close a Salesforce Bulk API Job using an API call:

  • Establish Authentication
    • Obtain a valid Salesforce access token using your preferred authentication method (e.g., OAuth 2.0, Session ID).
    • Include the access token in the header of your API calls.
  • Construct the API Endpoint
    • Form the endpoint URL for closing a job:
    • https://yourInstance.salesforce.com/services/async/vXX.X/job/jobId
    • Replace yourInstance with your Salesforce instance URL.
    • Replace XX.X with the Bulk API version you're using.
    • Replace jobId with the ID of the job you want to close.
  • Send a POST Request
    • Send a POST request to the constructed endpoint.
  • Include these headers
    • X-SFDC-Session: <yourAccessToken>
    • Content-Type: application/json

  • Specify Action
    • Set the action parameter in the request body to close.



  • Handle the Response
    • Parse the response from the API call.


    • Check for successful closure (HTTP status code 204) or errors (non-204 status codes).
    • Handle any errors appropriately.

Conclusion

The Close operation plays a vital role in ensuring the seamless completion of Bulk API jobs and maintaining data integrity within Salesforce. By understanding its importance and following best practices, users can maximize the efficiency and effectiveness of their Bulk API data integration processes.

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

Comments