Skip to content

Commit

Permalink
Merge pull request #358 from ballerina-platform/types
Browse files Browse the repository at this point in the history
Move salesforce types package into salesforce
  • Loading branch information
niveathika authored Aug 21, 2024
2 parents af2fdeb + 8ade43b commit ca9a578
Show file tree
Hide file tree
Showing 8 changed files with 31,469 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ concurrency:
cancel-in-progress: true

on: pull_request
env:
JAVA_OPTS: ${{ secrets.JAVA_OPTS }} -DmaxYamlCodePoints=99999999

jobs:
call_workflow:
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ distribution = "2201.8.0"
org = "ballerinax"
name = "salesforce"
version = "8.1.0"
export = ["salesforce", "salesforce.bulk", "salesforce.soap","salesforce.bulkv2", "salesforce.apex"]
export = ["salesforce", "salesforce.bulk", "salesforce.soap","salesforce.bulkv2", "salesforce.apex", "salesforce.types"]
license= ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["Sales & CRM/Customer Relationship Management", "Cost/Freemium"]
Expand Down
3 changes: 2 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
version = "1.6.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand Down Expand Up @@ -402,6 +402,7 @@ modules = [
{org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.bulk"},
{org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.bulkv2"},
{org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.soap"},
{org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.types"},
{org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.utils"}
]

2 changes: 1 addition & 1 deletion ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def stripBallerinaExtensionVersion(String extVersion) {
ballerina {
packageOrganization = packageOrg
module = project.packageName
testCoverageParam = "--code-coverage --coverage-format=xml"
testCoverageParam = "--code-coverage --coverage-format=xml --excludes='./modules/types/*.bal'"
isConnector = true
}

Expand Down
134 changes: 134 additions & 0 deletions ballerina/modules/types/Module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
## Overview

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](https://central.ballerina.io/ballerinax/salesforce/latest) 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.

## Setup Guide

To customize this project for your Salesforce account and include your custom SObjects, follow the steps below:

### Step 1: Login to Your Salesforce Developer Account

Begin by logging into your [Salesforce Developer Account](https://developer.salesforce.com/).

### Step 2: Generate Open API Specification for Your SObjects

#### Step 2.1: Initiate OpenAPI Document Generation

Use the following command to send a POST request to start the OpenAPI document generation process.

```bash
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.

#### Step 2.2: Retrieve the OpenAPI Document

Send a GET request to fetch the generated OpenAPI document using the following command.

```bash
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.

### Step 3: Configure Cluster Settings

To prevent Out-of-Memory (OOM) issues, execute the following command:

```bash
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.

1. Create a new Ballerina project, naming the project as desired (e.g., custom_types, salesforce_types, etc.).

```bash
bal new custom_types
```

2. Customize the package details by editing the `Ballerina.toml` file. For instance, you can modify the [package] section as follows:

```toml
[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.

4. Move the OpenAPI spec into the newly created project directory and execute the following command:

```bash
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.

### Step 4: Edit the Generated Client and Push it to Local Repository

#### Step 4.1 Delete the utils.bal and clients.bal files.

#### Step 4.2 Use the following commands to build, pack, and push the package:

````bash
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.

## Quickstart

To use the `salesforce.types` module in your Ballerina application, modify the `.bal` file as follows:

### Step 1: Import the package

Import `ballerinax/salesforce.types` module.

```ballerina
import ballerinax/salesforce;
import ballerinax/salesforce.types;
```

### Step 2: Instantiate a new client

Obtain the tokens using the following the [`ballerinax/salesforce` connector set up guide](https://central.ballerina.io/ballerinax/salesforce/latest). Create a salesforce:ConnectionConfig with the obtained OAuth2 tokens and initialize the connector with it.

```ballerina
salesforce:ConnectionConfig config = {
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};
salesforce:Client salesforce = new(config);
```

### Step 3: Invoke the connector operation

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.

```ballerina
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.

```bash
bal run
```
Loading

0 comments on commit ca9a578

Please sign in to comment.