Salesforce Bulk API is a specialized asynchronous RESTful API for loading and querying bulk of data at once. This module provides bulk data operations for CSV, JSON, and XML data types.
This module supports Salesforce Bulk API v1.
Before using this connector in your Ballerina application, complete the following:
- Create Salesforce account
- Obtain tokens - Follow the steps listed under OAuth 2.0 Web Server Flow for Web App Integration.
To use the Salesforce connector in your Ballerina application, update the .bal file as follows:
Import the ballerinax/salesforce.bulk
module into the Ballerina project.
import ballerinax/salesforce.bulk;
Create a ConnectionConfig
with the OAuth2 tokens obtained, and initialize the connector with it.
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string refreshUrl = ?;
configurable string baseUrl = ?;
bulk:ConnectionConfig sfConfig = {
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};
bulk:Client bulkClient = new (sfConfig);
- Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to insert bulk contacts using the connector.
json contacts = [
{
description: "Created_from_Ballerina_Sf_Bulk_API",
FirstName: "Morne",
LastName: "Morkel",
Title: "Professor Grade 03",
Phone: "0442226670",
Email: "[email protected]"
}
];
public function main() returns error? {
bulk:BulkJob insertJob = check bulkClient->createJob("insert", "Contact", "JSON");
bulk:BatchInfo batch = check bulkClient->addBatch(insertJob, contacts);
}
- Use
bal run
command to compile and run the Ballerina program.