ballerinax/salesforce Ballerina library

4.1.0

Overview

The Salesforce connector allows users to perform CRUD operations for SObjects, query using SOQL, search using SOSL, and describe SObjects and organizational data through the Salesforce REST API. Apart from these functionalities, Ballerina Salesforce Connector includes a listener to capture events.

This module supports Salesforce v48.0 REST API.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

  1. Create Salesforce account
  2. Obtain tokens

Quickstart

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

Client

Step 1: Import connector

Import the ballerinax/salesforce module into the Ballerina project.

Copy
import ballerinax/salesforce;

Step 2: Create a new connector instance

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

Copy
salesforce:ConnectionConfig sfConfig = {
   baseUrl: <"EP_URL">,
   clientConfig: {
     clientId: <"CLIENT_ID">,
     clientSecret: <"CLIENT_SECRET">,
     refreshToken: <"REFRESH_TOKEN">,
     refreshUrl: <"REFRESH_URL"> 
   }
};

salesforce:Client baseClient = 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 create a record using the connector.
Copy
json accountRecord = {
  Name: "John Keells Holdings",
  BillingCity: "Colombo 3"
};

public function main() returns error? {
  string recordId = check baseClient->createRecord("Account", accountRecord);
}
  1. Use bal run command to compile and run the Ballerina program.

Listener

Step 1: Import connector

Import the ballerinax/salesforce module into the Ballerina project.

Copy
import ballerinax/salesforce;

Step 2: Create a new connector listener instance

Create a salesforce:ListenerConfiguration with the basic credentials obtained, and initialize the connector with it. The password should be the concatenation of the user's Salesforce password and secret key.

Copy
salesforce:ListenerConfiguration listenerConfig = {
  username: config:getAsString("SF_USERNAME"),
  password: config:getAsString("SF_PASSWORD")
};
listener salesforce:Listener eventListener = new (listenerConfig);

Step 3: Invoke listener service

  1. Now you can use the channel available in the Salesforce and capture the events occurred.
    Following is an example on how to capture all events using the connector.
Copy
@salesforce:ServiceConfig {
    channelName:"/data/ChangeEvents"
}
service /quoteUpdate on eventListener {
    remote function onUpdate (salesforce:EventData quoteUpdate) { 
        json quote = quoteUpdate.changedData.get("Status");
    }
}
  1. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Import

import ballerinax/salesforce;Copy

Metadata

Released date: almost 3 years ago

Version: 4.1.0

License: Apache-2.0


Compatibility

Platform: java11

Ballerina version: 2201.0.0


Pull count

Total: 95249

Current verison: 63893


Weekly downloads


Source repository


Keywords

Sales & CRM/Customer Relationship Management

Cost/Freemium


Contributors

Other versions

See more...