Salesforce REST API provides CRUD operations for SObjects, query using SOQL, search using SOSL, and describe SObjects and organizational data.
This module supports Salesforce v48.0 REST API.
Before using this connector in your Ballerina application, complete the following:
- Create Salesforce account
- Obtain tokens
- Client tokens - Follow the steps listed under OAuth 2.0 Web Server Flow for Web App Integration.
- Listener tokens - Follow the steps listed under Reset Your Security Token generate secret key and follow the steps listed under Subscription Channels to subscribe channels.
To use the Salesforce connector in your Ballerina application, update the .bal file as follows:
Import the ballerinax/salesforce
module into the Ballerina project.
import ballerinax/salesforce;
Create a salesforce: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 = ?;
salesforce:ConnectionConfig sfConfig = {
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};
salesforce:Client baseClient = 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 create a record using the connector.
record{} accountRecord = {
"Name": "IT World",
"BillingCity": "Colombo 1"
};
public function main() returns error? {
salesforce:CreationResponse res = check baseClient->create("Account", accountRecord);
}
- Use
bal run
command to compile and run the Ballerina program.