Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    • Enhancing Performance with File Compression in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Tuesday, May 20
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Architecture»Using Salesforce Bulk API V2

    Using Salesforce Bulk API V2

    Dhanik Lal SahniBy Dhanik Lal SahniDecember 26, 2020Updated:June 11, 2023No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Using Salesforce Bulk API V2
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Salesforce Bulk API is used primarily for data migration or data upload. Bulk API has two versions to support data upload. Bulk API V1.0 is custom REST API and V2.0 is standard REST API. Bulk API V2.0 will support all features of REST API like stateless, cacheable , simple to use and etc.

    Below are some benefits of Bulk API V2.0

    1. Bulk API 2.0 provides a simple interface to quickly load large amounts of data into your Salesforce org and to perform bulk queries on your org data.
    2. Bulk API 2.0 supports all OAuth flows supported by other Salesforce REST APIs.
    3. Bulk API 2.0 simplifies uploading large amounts of data by breaking the data into batches automatically. All we have to do is upload a CSV file with record data and check back when the results are ready.
    4. Instead of limiting the amount of data uploaded daily by the quantity of jobs, Bulk API 2.0 uses a limit of total records uploaded

    Difference between Bulk API V1.0 and V2.0:

    Bulk API V1.0 can also process records but there is some advantage in Bulk API v2.0. Below is some important difference between Bulk API V1.0 and V2.0

    BULK API 1.0BULK API 2.0
    Batch need to create manuallyNo need to create batch. System will do this internally.
    Limits on number of record, file size and batchBased on daily limit in 24 hr hour
    Built on custom REST framework so not like other REST API IntegrationBuilt on standard REST API so similar to other REST API integration
    Support serial and parallel processingSupport only parallel processing

    Let us see how we can use Bulk API V2.0 using POSTMAN. Similar to POSTMAN, we can utilize these API calls from other applications like .NET, Java, SAP etc.

    For processing records in Bulk API v2.0 we need below steps

    1. Get Access token.
    2. Create bulk job
    3. Add batch to job
    4. Close job to start processing
    5. Get Job Status

    As we need to call Salesforce using REST API, we have to create connected app. See our last post for this.

    Along with connected app, we need to share user credential with client or caller. Before sharing user credential, review profile/permission set of that user. Caller should only able to use REST API of your org and only required permission should be given. This is required for securing your org.

    Let us start above mentioned steps one by one

    1. Get Access token

    As we need to call Salesforce Org REST APIs, we need access token for that. This step will get access token from Salesforce Org so that subsequent call can use that token to create/upload bulk job.

    Below request detail will be sent from POSTMAN/client apps to get access token. If you use sand box then use https://test.salesforce.com For developer and production environment we will use https://login.salesforce.com.

    Request Detailvalues
    Endpoint Urlhttps://login.salesforce.com/services/oauth2/token
    Http MethodPOST
    Params 
    grant_typePassword
    client_id{{connected app client_id}}
    client_secret{{connected app client_secret}}
    Username{{username of salesforce}}
    Password{{password of saleforce user}}
    Bulk API V2.0- SalesforceCodex

    After submitting these detail to endpoint url we will get access token and salesforce org instance name. These will be used in next step to frame REST API url and headers.

    2. Create Bulk Job

    Once we get access token, we will able to call bulk api. For uploading records, we have to create bulk job first. As this will be REST API call, we have to provided access token which we have received in first step.

    In this step, we have to provide- what kind of operation we are performing, which object will be used to upload records.

    Request Detailvalues
    Login Url{{instanceUrl from first step response}}/services/data/v50.0/jobs/ingest/
    Http MethodPOST
    Headers 
    Content-Typeapplication/json; charset=UTF-8
    Acceptapplication/json
    Authorization{{access_token from first step response}}
    Body(raw) {
        “object” : “Account”,
        “contentType” : “CSV”,
        “operation” : “insert”,
        “lineEnding”: “CRLF”
    }
    BulkAPI2_createjob_SalesforceCodex

    On submitting above request detail, we will get job id (indicate in above image). This job id will be required along with access token in next steps.

    3. Add batch to job

    As we are able to create job in previous step, now we have to upload record in that job to process records. Records can be uploaded in two ways, using CSV file upload and upload records directly in API request body. Use any method to upload record.

    Based on uploaded record count, system automatically divide in batches. In V1.0 we have to upload multiple batches and keep track of each batch. Here in V2.0, we don’t require to create multiple batches.

    Request Detailvalues
    Login Url{{instanceUrl from first step response}}/services/data/v50.0/jobs/ingest/{{jobid from create job step}}/batches/
    Http MethodPUT
    Headers 
    Content-Typeapplication/json; charset=UTF-8
    Acceptapplication/json
    Authorization{{access_token from first step response}}
    Body(binary)    Select csv file to upload  
    Body(raw)Name,FirstName__c,LastName__c,Phone,Email__c
    Samson,Samson,Williamson,1-741-812-6068,Cum@congueelit.net
    BulkAPI2_upload_SalesforceCodex

    4. Close job to start processing

    Once records are uploaded, we need to close job. This will indicate that system can now start processing records. Based on number of records uploaded, system will create batch internally.

    Request Detailvalues
    Login Url{{instanceUrl from first step response}}/services/data/v50.0/jobs/ingest/{{jobid}}/
    Http MethodPATCH
    Headers 
    Content-Typeapplication/json; charset=UTF-8
    Authorization{{access_token from first step response}}
    Body(raw){
        “state” : “UploadComplete”
    }

    On submitting it will be object detail and type of operation we have performed. It will also indicate job state.

    Salesforce Bulk API V2

    5. Get Job Status

    Once job is closed and if we want to check status of record processing, we can get status using API.

    Request Detailvalues
    Login Url{{instanceUrl from first step response}}/ /services/data/v50.0/jobs/ingest/{{jobid}}/
    Http MethodGET
    Headers 
    Content-Typeapplication/json; charset=UTF-8
    Authorization{{access_token from first step response}}

    Above request will give current status of job. In below image, it is showing status as JobComplete.

    Salesforce Bulk API V2

    References:

    https://developer.salesforce.com/docs/atlas.en-us.api_bulk_v2.meta/api_bulk_v2/

    https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_concepts_limits.htm

    Related Posts

    USING SALESFORCE BULK API V1

    apex rest bulk api bulk api v1 Bulk api v2 BulkAPI integration integration architecture rest api salesforce salesforce bulk api
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleGenerate Public Link for Salesforce file
    Next Article Named Entity Recognition using Salesforce Einstein API
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    By Dhanik Lal Sahni5 Mins Read

    How to Implement Dynamic Queueable Chaining in Salesforce Apex

    April 21, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.