Salesforce is a leading customer relationship management (CRM) platform that helps businesses manage and streamline their sales, service, and marketing operations. The Ballerina Salesforce Connector is a project designed to enhance integration capabilities with Salesforce by providing a seamless connection for Ballerina. Notably, this Ballerina project incorporates record type definitions for the base types of Salesforce objects, offering a comprehensive and adaptable solution for developers working on Salesforce integration projects.
To customize this project for your Salesforce account and include your custom SObjects, follow the steps below:
Begin by logging into your Salesforce Developer Account.
Use the following command to send a POST request to start the OpenAPI document generation process.
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
https://MyDomainName.my.salesforce.com/services/data/vXX.X/async/specifications/oas3 \
-d '{"resources": ["*"]}'
Replace YOUR_ACCESS_TOKEN and MyDomainName with your actual access token and Salesforce domain. If successful, you'll receive a response with a URI. Extract the locator ID from the URI.
Send a GET request to fetch the generated OpenAPI document using the following command.
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
https://MyDomainName.my.salesforce.com/services/data/vXX.X/async/specifications/oas3/LOCATOR_ID -o oas.json
Replace YOUR_ACCESS_TOKEN, MyDomainName, and LOCATOR_ID with your actual values.
To prevent Out-of-Memory (OOM) issues, execute the following command:
export JAVA_OPTS="$JAVA_OPTS -DmaxYamlCodePoints=99999999"
Generate the Ballerina project for the OpenAPI spec using the Ballerina Open API tool with the following commands.
- Create a new Ballerina project, naming the project as desired (e.g., custom_types, salesforce_types, etc.).
bal new custom_types
- Customize the package details by editing the
Ballerina.toml
file. For instance, you can modify the [package] section as follows:
[package]
org = "example"
name = "salesforce.types"
version = "0.1.0"
Feel free to replace "salesforce.types" with one of the suitable desired names like "custom.types" or "integration.types," or come up with your own unique package name.
- Move the OpenAPI spec into the newly created project directory and execute the following command:
bal openapi -i oas.json --mode client --client-methods resource
This will generate the Ballerina project structure, record types that correspond to the SObject definitions, and client methods based on the provided OpenAPI specification.
bal pack
bal push --repository=local
By following these steps, you can set up and customize the Ballerina Salesforce Connector for your Salesforce account with ease.
To use the salesforce.types
module in your Ballerina application, modify the .bal
file as follows:
Import ballerinax/salesforce.types
module.
import ballerinax/salesforce;
import ballerinax/salesforce.types;
Obtain the tokens using the following the ballerinax/salesforce
connector set up guide. Create a salesforce:ConnectionConfig with the obtained OAuth2 tokens and initialize the connector with it.
salesforce:ConnectionConfig config = {
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};
salesforce:Client salesforce = new(config);
Now you can utilize the available operations. Note that they are in the form of remote operations. Following is an example on how to create a record using the connector.
salesforce:Client salesforce = check new (config);
stypes:AccountSObject response = {
Name: "IT World",
BillingCity: "New York"
};
salesforce:CreationResponse response = check salesforce->create("Account", response);
Use following command to compile and run the Ballerina program.
bal run
The Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library parent repository.
This repository only contains the source code for the package.
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOME
environment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
salesforce.types
package. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.