Salesforce Bulk API 2.0
- Omar Al Qweider

- Mar 27, 2019
- 2 min read
Updated: Dec 22, 2024
Do you need to mass update or modify millions of records in Salesforce in one go? No problem, Salesforce provides an Out Of The Box way to accomplish this task which is called Bulk API 2.0. Bulk API 2.0 is a very easy and powerful way to integrate your Salesforce org with an external application that needs to execute operations (e.g. insert, upsert) to a large number of records (think at hundreds of thousands or millions of records in one go).
Please refer to the Salesforce official documentation here to understand how that works. I also found a useful Salesforce blog here which compares Bulk API 1.0 to Bulk API 2.0 and provides the high level steps that are required to implement Bulk API 2.0.
Few things to remember:
1. Security comes first: Pay attention to all the security configurations required for the Connected App e.g. Profile, IP restrictions, scope, refresh token policies. In particular choose the right OAuth 2.0 flow to authenticate and authorize access to your salesforce org. This is extremely important as each OAuth 2.0 flow is designed to support specific use cases, any deviation from the Salesforce guidance could imply security risks. You can learn more about OAuth 2.0 here.
2. Relationships are important: Relationships are important in life and Salesforce is not an exception to this. Firstly if you need to create records that are related to each other, establish the order with which the csv files will be sent to SF based on the relationships in your data model (e.g. first parent records then related child records).
Also remember you could use external ids to create relationships with a parent record (that is valid for Master Detail and Lookup relationships). By using external IDs, you can avoid extracting Salesforce IDs and adding them to your CSV files.
In the Account/Opportunity example below you could use a column 'Account.External_id__c' in your csv for Opportunities to form a relationship with existing Accounts (Account records should be created first).

Also remember that the name of the relationship field for standard fields might not be exactly the same as you would expect therefore use workbench to get the correct relationship name. E.g. use GET method on the url:/services/data/v44.0/sobjects/Opportunity/describe to get the definition of fields for Opportunity object and navigate to the relationship field of interest. In this example 'AccountId' is the field name and 'Account' is the relationship name.

3. E2E Testing: The fact that records are created in your org does not guarantee the correct data have been created. You will need to apply automated/manual testing to make sure the data is correctly represented as you were expecting, remember this process is going to affect millions of records in your Salesforce org.


Comments