DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Why Database Migrations Take Months and How to Speed Them Up
  • 5 Key Steps for a Successful Cloud Migration Strategy
  • Introduction to Salesforce Batch Apex [Video]
  • Data Migration With AWS DMS and Terraform IaC

Trending

  • Rust, WASM, and Edge: Next-Level Performance
  • Scaling Microservices With Docker and Kubernetes on Production
  • Using Java Stream Gatherers To Improve Stateful Operations
  • Advancing Your Software Engineering Career in 2025
  1. DZone
  2. Data Engineering
  3. Data
  4. Salesforce Bulk API 2.0: Streamlining Large-Scale Data Operations

Salesforce Bulk API 2.0: Streamlining Large-Scale Data Operations

Manage millions of data operations within Salesforce in a simple, reliable, and performative way using the Bulk API 2.0.

By 
Jaseem Pookandy user avatar
Jaseem Pookandy
DZone Core CORE ·
Jul. 11, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.7K Views

Join the DZone community and get the full member experience.

Join For Free

Have you ever faced the challenge of managing large data operations within Salesforce, such as updating, inserting, deleting, or querying records? These operations might arise from one-time data migration projects or ongoing data integration needs with external systems. In such scenarios, Salesforce Bulk API 2.0 is your solution. This robust API is designed to handle large-scale data operations efficiently, simplifying and streamlining the process.

Salesforce Bulk API 2.0 is a REST-based API, that runs the requested operation asynchronously. It is designed to simplify bulk operations within Salesforce as well as to improve the performance and reliability of bulk data processing. The following are key features of Bulk API 2.0. 

1. Simplified Bulk Data Management

You only need to create one job for each data operation and Salesforce will handle breaking down the data set into multiple batches. This significantly reduces the time and effort needed for large data migrations or batch operations. 

2. Reliability and Performance

Salesforce optimizes internal batch splits and execution for you. Salesforce also automatically executes retries when an error occurs and supports partial data processing. This means that even if some records fail, the successful ones are processed, and users receive clear feedback on the errors encountered. 

3. Asynchronous Processing

Bulk API 2.0 processes the requests asynchronously, meaning the batches run in the background. This allows users to continue with other tasks without waiting for the operation to complete. 

4. Supports JSON

The API supports JSON format for job creation and status checks. 

How To Use Bulk API 2.0

To use Bulk API 2.0, you need to follow the following steps. Let us take an example of an update operation on the Opportunity table.   

1. Create a Job

The first step is to create the job with operation = update, by sending a POST request with the following details. 

endpoint:  /services/data/vXX.X/jobs/ingest

payload: lineEnding request parameter is the line-ending format used in the CSV. The API supports two line-ending formats: linefeed (LF), and carriage-return plus linefeed (CRLF). 

JSON
 
{
    "object" : "Opportunity",
    "contentType" : "CSV",
    "operation" : "update",
    "lineEnding" : "LF"
}


response: You will get the response with the job ID. You will be using this Job ID in further steps. The status of the job is 'Open'. 

workbench

You can also go to Setup>Monitor Bulk Data Load Jobs to monitor the progress of the jobs.

You can also go to Setup>Monitor Bulk Data Load Jobs to monitor the progress of the jobs

2. Upload Data

Once the job is created, the next step is to upload your data that needs an update. You need to send a PUT request to the following endpoint, with the data for the job in CSV format. You can upload up to 150 MB of data per job. 

endpoint: /services/data/vXX.X/jobs/ingest/{jobId}/batches

raw response

3. Set Job State to Uploadcomplete

Once the upload is complete, notify Salesforce servers that it is time to process the data.  To do this, send a PATCH request to the following endpoint. 

endpoint: /services/data/vXX.X/jobs/ingest/{jobId}/

payload: 

JSON
 
{ "state" : "UploadComplete" }

upload complete

response: Job status is changed to UploadComplete. 

4. Check the Status

If you want to check the status of the job and, the number of records processed, errored out, and unprocessed, you can send a GET request to the following endpoint. 

endpoint: /services/data/vXX.X/jobs/ingest/{jobId}

response: 

JSON
 
{ "id" : "7505fEXAMPLE4C2AAM",
"operation" : "update",
"object" : "Opportunity",
"createdById" : "0055fEXAMPLEtG4AAM",
"createdDate" : "2022-01-02T21:33:43.000+0000",
"systemModstamp" : "2022-01-02T21:38:31.000+0000",
"state" : "JobComplete",
"concurrencyMode" : "Parallel",
"contentType" : "CSV",
 "apiVersion" : 61.0,
"jobType" : "V2Ingest",
"lineEnding" : "LF",
"columnDelimiter" : "COMMA",
"numberRecordsProcessed" : 7,
"numberRecordsFailed" : 0,    
"retries" : 0,
"totalProcessingTime" : 886,
"apiActiveProcessingTime" : 813,
"apexProcessingTime" : 619 }


You can also send a GET request to /services/data/vXX.X/jobs/ingest/{jobId}/failedResults endpoint to get the details of the failed records OR 

to /services/data/v61.0/jobs/ingest/{jobId}/successfulResults/

endpoint to get details about which records were successfully processed.

Use Cases of Bulk API 2.0

Data Migration

Bulk API 2.0 is ideal for migrating large data sets from legacy systems to Salesforce. Its ability to process millions of data efficiently makes it the first option for large-scale operations. 

Data Integration

When you have data integration requirements, integrating external systems to Salesforce, Bulk API 2.0 provides a robust solution. Its support for asynchronous processing makes large-scale data integration efficient, as it ensures that data can be integrated without disrupting ongoing operations. 

Batch Processing

Routine batch processing jobs, such as nightly data cleanups, can be streamlined using Bulk API 2.0. Its error-handling capabilities make it ideal for routine data operations. 

Conclusion

Salesforce Bulk API 2.0 is a critical tool for organizations to manage large-scale data operations efficiently. Its capability to process millions of data effectively, with robust error handling and support for asynchronous processing, makes this a go-to tool for any data migration, data integration, or batch processing projects.

Batch processing Data integration Data migration Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Why Database Migrations Take Months and How to Speed Them Up
  • 5 Key Steps for a Successful Cloud Migration Strategy
  • Introduction to Salesforce Batch Apex [Video]
  • Data Migration With AWS DMS and Terraform IaC

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!