ballerinax/salesforce.bulk Ballerina library

8.0.0

Overview

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.

Setup guide

  1. Create a Salesforce account with the REST capability.

  2. Go to Setup --> Apps --> App Manager

    Setup Side Panel
  3. Create a New Connected App.

    Create Connected Apps Create Connected Apps
  4. After the creation user can get consumer key and secret through clicking on the Manage Consume Details button.

    Consumer Secrets
  5. Next step would be to get the token.

    • Log in to salesforce in your prefered browser and enter the following url. https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<CONSUMER_KEY>&redirect_uri=<REDIRECT_URL>

    • Allow access if an alert pops up and the browser will be redirected to a Url like follows. https://login.salesforce.com/?code=<ENCODED_CODE>

    • The code can be obtained after decoding the encoded code

  6. Get Access and Refresh tokens

    • Following request can be sent to obtain the tokens curl -X POST https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<CONSUMER_KEY>&client_secret=<CONSUMER_SECRET>&redirect_uri=https://test.salesforce.com/
    • Tokens can be obtained from the response.

Quickstart

To use the Salesforce connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/salesforce.bulk module into the Ballerina project.

Copy
import ballerinax/salesforce.bulk;

Step 2: Create a new connector instance

Create a ConnectionConfig with the OAuth2 tokens obtained, and initialize the connector with it.

Copy
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);

Step 3: Invoke connector operation

  1. 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.
Copy
json contacts = [
    {
        description: "Created_from_Ballerina_Sf_Bulk_API",
        FirstName: "Morne",
        LastName: "Morkel",
        Title: "Professor Grade 03",
        Phone: "0442226670",
        Email: "morne89@gmail.com"
    }
];

public function main() returns error? {
    bulk:BulkJob insertJob = check bulkClient->createJob("insert", "Contact", "JSON");

    bulk:BatchInfo batch = check bulkClient->addBatch(insertJob, contacts);
}
  1. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Import

import ballerinax/salesforce.bulk;Copy

Metadata

Released date: 3 months ago

Version: 8.0.0

License: Apache-2.0


Compatibility

Platform: java17

Ballerina version: 2201.8.4

GraalVM compatible: Yes


Pull count

Total: 94252

Current verison: 39


Weekly downloads


Source repository


Keywords

Sales & CRM/Customer Relationship Management

Cost/Freemium


Contributors

Other versions

See more...