diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b694bfc5..dd9d7182 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,4 @@ # See: https://help.github.com/articles/about-codeowners/ # These owners will be the default owners for everything in the repo. -* @indikasampath2000 @abeykoon @sachinira +* @aashikam @niveathika @sahanHe diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml new file mode 100644 index 00000000..7a863b91 --- /dev/null +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -0,0 +1,21 @@ +name: GraalVM Check + +on: + schedule: + - cron: "30 18 * * *" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + +jobs: + call_stdlib_workflow: + name: Run StdLib Workflow + if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@main + secrets: inherit + with: + additional-build-flags: "-x :salesforce-examples:build" + + \ No newline at end of file diff --git a/.github/workflows/build-with-bal-test-native.yml b/.github/workflows/build-with-bal-test-native.yml deleted file mode 100644 index aec9384a..00000000 --- a/.github/workflows/build-with-bal-test-native.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: GraalVM Check - -on: - schedule: - - cron: '30 18 * * *' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - - name: Set up GraalVM - uses: graalvm/setup-graalvm@v1 - with: - java-version: '17' - distribution: 'graalvm-community' - github-token: ${{ secrets.GITHUB_TOKEN }} - set-java-home: 'false' - - - name: Check GraalVM installation - run: | - echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" - echo "JAVA_HOME: ${{ env.JAVA_HOME }}" - native-image --version - - - name: Run Ballerina tests using the native executable - run: bal test --graalvm ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} - EP_URL: ${{ secrets.EP_URL }} - REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - REFRESH_URL: ${{ secrets.REFRESH_URL }} diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index ca62ce51..23e19ecc 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -2,71 +2,15 @@ name: Daily build on: schedule: - - cron: '30 2 * * *' + - cron: "30 2 * * *" jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm + call_workflow: + name: Run Daily Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/daily-build-connector-template.yml@main + secrets: inherit + with: + repo-name: module-ballerinax-sfdc - # Test Ballerina Project - - name: Ballerina Test - run: bal test --test-report --code-coverage --coverage-format=xml ./ballerina - env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} - EP_URL: ${{ secrets.EP_URL }} - REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - REFRESH_URL: ${{ secrets.REFRESH_URL }} - JAVA_HOME: /usr/lib/jvm/default-jvm - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - - # Send notification when build fails - - name: Notify failure - if: ${{ failure() }} - run: | - curl -X POST \ - 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ - -H 'Accept: application/vnd.github.v3+json' \ - -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ - --data "{ - \"event_type\": \"notify-build-failure\", - \"client_payload\": { - \"repoName\": \"module-ballerinax-sfdc\" - } - }" + \ No newline at end of file diff --git a/.github/workflows/dev-stg-release.yml b/.github/workflows/dev-stg-release.yml index d97015c6..ff192905 100644 --- a/.github/workflows/dev-stg-release.yml +++ b/.github/workflows/dev-stg-release.yml @@ -1,72 +1,23 @@ -name: Dev/Staging BCentral Release +name: Publish to the Ballerina Dev\Stage Central on: workflow_dispatch: inputs: - bal_central_environment: - description: Ballerina Central Environment + environment: type: choice - options: - - STAGE - - DEV + description: Select Environment required: true + options: + - DEV CENTRAL + - STAGE CENTRAL jobs: - release: - runs-on: ubuntu-latest - env: - BALLERINA_${{ github.event.inputs.bal_central_environment }}_CENTRAL: true - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17.0.7 - - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: 2201.8.0 - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test -x :salesforce-examples:build - - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - - name: Push to Staging - if: github.event.inputs.bal_central_environment == 'STAGE' - working-directory: ./ballerina - run: bal push - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm - - - name: Push to Dev - if: github.event.inputs.bal_central_environment == 'DEV' - run: bal push - working-directory: ./ballerina - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm + call_workflow: + name: Run Dev\Stage Central Publish Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/dev-stage-central-publish-connector-template.yml@main + secrets: inherit + with: + environment: ${{ github.event.inputs.environment }} + additional-publish-flags: "-x :salesforce-examples:build" + \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 81fed605..abfb0be9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,57 +1,15 @@ -name: CI_pull_request +name: PR Build -on: [ pull_request ] +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest +on: pull_request - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - # Test Ballerina Project - - name: Ballerina Test - # tests will be skipped if the PR is from a forked repository (as the secrets are not available) - if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} - run: bal test --test-report --code-coverage --coverage-format=xml ./ballerina - env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} - EP_URL: ${{ secrets.EP_URL }} - REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - REFRESH_URL: ${{ secrets.REFRESH_URL }} - JAVA_HOME: /usr/lib/jvm/default-jvm - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 +jobs: + call_workflow: + name: Run PR Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/pr-build-connector-template.yml@main + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07d8392d..b7d76cd3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,62 +1,18 @@ -name: Deployment +name: Publish Release on: - release: - types: [ published ] + workflow_dispatch: jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: 2201.8.0 - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test -x :salesforce-examples:build - - # Perform Trivy scan - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - # Push to Ballerina Central - - name: Ballerina Push - run: bal push - working-directory: ./ballerina - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm + call_workflow: + name: Run Release Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/release-package-connector-template.yml@main + secrets: inherit + with: + package-name: salesforce + package-org: ballerinax + additional-build-flags: "-x :salesforce-examples:build" + additional-release-flags: "-x :salesforce-examples:build" + additional-publish-flags: "-x :salesforce-examples:build" + \ No newline at end of file diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 552dd249..ac15a675 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -3,38 +3,13 @@ name: Trivy on: workflow_dispatch: schedule: - - cron: '30 20 * * *' + - cron: "30 20 * * *" jobs: - ubuntu-build: - name: Build on Ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: 17.0.7 - - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build -x check -x test -x :salesforce-examples:build - - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' + call_workflow: + name: Run Trivy Scan Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main + secrets: inherit + with: + additional-build-flags: "-x :salesforce-examples:build -Pgroups=mock" diff --git a/README.md b/README.md index 5d394cdd..0000d244 100644 --- a/README.md +++ b/README.md @@ -112,15 +112,15 @@ bal run ## Examples -The `salesforce` integration samples illustrate its usage in various integration scenarios. Explore these examples below, covering the use of salesforce APIs in integrations. +The `salesforce` connector provides practical examples illustrating usage in various scenarios. Explore these examples below, covering use cases like creating sObjects, retrieving records, and executing bulk operations. -1. [FTP B2B EDI message to Salesforce opportunity](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/ftp-edi-message-to-salesforce-opportunity) - This example reads EDI files from a given FTP location, converts those EDI messages to Ballerina records and creates a Salesforce opportunity for each EDI message. +1. [Salesforce REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/rest_api_usecases) - How to employ REST API of Salesforce to carryout varies tasks. -2. [Salesforce new contact to Twilio SMS](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/salesforce-new-contact-to-twilio-sms) - This example sends a Twilio SMS for every new Salesforce contact. +2. [Salesforce Bulk API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/bulk_api_usecases) - How to employ Bulk API of Salesforce to execute Bulk jobs. -3. [Kafka message to Salesforce new Contact](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update) - This example updates the product price in the Salesforce price book through Kafka and Salesforce integration. +3. [Salesforce Bulk v2 API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/bulkv2_api_usecases) - How to employ Bulk v2 API to execute an ingest job. -4. [Email Lead info into Salesforce using OpenAI](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/gmail-to-salesforce-lead) - This example creates a lead on Salesforce for each email marked with a specific label on Gmail using the OpenAI chat API to infer customer details. +4. [Salesforce APEX REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/apex_rest_api_usecases) - How to employ APEX REST API to create a case in Salesforce. ## Report Issues diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index e850dc7b..3a86e41b 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ distribution = "2201.8.0" org = "ballerinax" name = "salesforce" -version = "7.6.0" +version = "8.0.0" export = ["salesforce", "salesforce.bulk", "salesforce.soap"] license= ["Apache-2.0"] authors = ["Ballerina"] @@ -17,7 +17,7 @@ observabilityIncluded = true graalvmCompatible = true [[platform.java11.dependency]] -path = "../native/build/libs/salesforce-native-7.6.0.jar" +path = "../native/build/libs/salesforce-native-8.0.0.jar" groupId = "io.ballerinax" artifactId = "salesforce" -version = "7.6.0" +version = "8.0.0" diff --git a/ballerina/Module.md b/ballerina/Module.md index e289a3ae..a36ef581 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -82,7 +82,7 @@ Following is an example on how to create a record using the connector. ```ballerina salesforce:CreationResponse response = check - baseClient->create("Account", { + salesforce->create("Account", { "Name": "IT World", "BillingCity": "New York" }); @@ -97,12 +97,12 @@ bal run ## Examples -The `salesforce` integration samples illustrate its usage in various integration scenarios. Explore these examples below, covering the use of salesforce APIs in integrations. +The `salesforce` connector provides practical examples illustrating usage in various scenarios. Explore these examples below, covering use cases like creating sObjects, retrieving records, and executing bulk operations. -1. [FTP B2B EDI message to Salesforce opportunity](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/ftp-edi-message-to-salesforce-opportunity) - This example reads EDI files from a given FTP location, converts those EDI messages to Ballerina records and creates a Salesforce opportunity for each EDI message. +1. [Salesforce REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/rest_api_usecases) - How to employ REST API of Salesforce to carryout varies tasks. -2. [Salesforce new contact to Twilio SMS](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/salesforce-new-contact-to-twilio-sms) - This example sends a Twilio SMS for every new Salesforce contact. +2. [Salesforce Bulk API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/bulk_api_usecases) - How to employ Bulk API of Salesforce to execute Bulk jobs. -3. [Kafka message to Salesforce new Contact](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update) - This example updates the product price in the Salesforce price book through Kafka and Salesforce integration. +3. [Salesforce Bulk v2 API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/revamp-2023/examples/bulkv2_api_usecases) - How to employ Bulk v2 API to execute an ingest job. -4. [Email Lead info into Salesforce using OpenAI](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/gmail-to-salesforce-lead) - This example creates a lead on Salesforce for each email marked with a specific label on Gmail using the OpenAI chat API to infer customer details. +4. [Salesforce APEX REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/revamp-2023/examples/apex_rest_api_usecases) - How to employ APEX REST API to create a case in Salesforce. diff --git a/ballerina/Package.md b/ballerina/Package.md index 9ef62326..c417811f 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -93,10 +93,14 @@ bal run The `salesforce` integration samples illustrate its usage in various integration scenarios. Explore these examples below, covering the use of salesforce APIs in integrations. -1. [FTP B2B EDI message to Salesforce opportunity](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/ftp-edi-message-to-salesforce-opportunity) - This example reads EDI files from a given FTP location, converts those EDI messages to Ballerina records and creates a Salesforce opportunity for each EDI message. +## Examples + +The `salesforce` connector provides practical examples illustrating usage in various scenarios. Explore these examples below, covering use cases like creating sObjects, retrieving records, and executing bulk operations. + +1. [Salesforce REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/rest_api_usecases) - How to employ REST API of Salesforce to carryout varies tasks. -2. [Salesforce new contact to Twilio SMS](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/salesforce-new-contact-to-twilio-sms) - This example sends a Twilio SMS for every new Salesforce contact. +2. [Salesforce Bulk API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/bulk_api_usecases) - How to employ Bulk API of Salesforce to execute Bulk jobs. -3. [Kafka message to Salesforce new Contact](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update) - This example updates the product price in the Salesforce price book through Kafka and Salesforce integration. +3. [Salesforce Bulk v2 API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/bulkv2_api_usecases) - How to employ Bulk v2 API to execute an ingest job. -4. [Email Lead info into Salesforce using OpenAI](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/gmail-to-salesforce-lead) - This example creates a lead on Salesforce for each email marked with a specific label on Gmail using the OpenAI chat API to infer customer details. +4. [Salesforce APEX REST API use cases](https://github.com/ballerina-platform/module-ballerinax-sfdc/tree/main/examples/apex_rest_api_usecases) - How to employ APEX REST API to create a case in Salesforce. diff --git a/ballerina/modules/bulk/tests/bulk_csv_insert.bal b/ballerina/modules/bulk/tests/bulk_csv_insert.bal index 90654606..34ae74e0 100644 --- a/ballerina/modules/bulk/tests/bulk_csv_insert.bal +++ b/ballerina/modules/bulk/tests/bulk_csv_insert.bal @@ -176,7 +176,7 @@ function insertCsvFromFile() { log:printInfo("baseClient -> insertCsvFromFile"); string batchId = ""; - string csvContactsFilePath = "ballerina/modules/bulk/tests/resources/contacts1.csv"; + string csvContactsFilePath = "modules/bulk/tests/resources/contacts1.csv"; //create job error|BulkJob insertJob = baseClient->createJob("insert", "Contact", "CSV"); @@ -323,7 +323,7 @@ function insertCsvStringArrayFromFile() returns error? { log:printInfo("baseClient -> insertCsvStringArrayFromFile"); string batchId = ""; - string csvContactsFilePath = "ballerina/modules/bulk/tests/resources/contacts2.csv"; + string csvContactsFilePath = "modules/bulk/tests/resources/contacts2.csv"; //create job error|BulkJob insertJob = baseClient->createJob("insert", "Contact", "CSV"); @@ -464,7 +464,7 @@ function insertCsvStreamFromFile() returns error? { log:printInfo("baseClient -> insertCsvStreamFromFile"); string batchId = ""; - string csvContactsFilePath = "ballerina/modules/bulk/tests/resources/contacts3.csv"; + string csvContactsFilePath = "modules/bulk/tests/resources/contacts3.csv"; //create job error|BulkJob insertJob = baseClient->createJob("insert", "Contact", "CSV"); diff --git a/ballerina/modules/bulk/tests/bulk_json_insert.bal b/ballerina/modules/bulk/tests/bulk_json_insert.bal index 58a5eb33..a11f174b 100644 --- a/ballerina/modules/bulk/tests/bulk_json_insert.bal +++ b/ballerina/modules/bulk/tests/bulk_json_insert.bal @@ -187,7 +187,7 @@ function insertJson() returns error? { function insertJsonFromFile() returns error? { log:printInfo("baseClient -> insertJsonFromFile"); string jsonBatchId = ""; - string jsonContactsFilePath = "ballerina/modules/bulk/tests/resources/contacts.json"; + string jsonContactsFilePath = "modules/bulk/tests/resources/contacts.json"; //create job BulkJob jsonInsertJob = check baseClient->createJob("insert", "Contact", "JSON"); diff --git a/ballerina/modules/bulk/tests/bulk_xml_insert.bal b/ballerina/modules/bulk/tests/bulk_xml_insert.bal index ada788d9..32685fc1 100644 --- a/ballerina/modules/bulk/tests/bulk_xml_insert.bal +++ b/ballerina/modules/bulk/tests/bulk_xml_insert.bal @@ -167,7 +167,7 @@ function insertXmlFromFile() returns error? { log:printInfo("baseClient -> insertXmlFromFile"); string xmlBatchId = ""; - string xmlContactsFilePath = "ballerina/modules/bulk/tests/resources/contacts.xml"; + string xmlContactsFilePath = "modules/bulk/tests/resources/contacts.xml"; //create job BulkJob xmlInsertJob = check baseClient->createJob("insert", "Contact", "XML"); diff --git a/ballerina/modules/bulk/tests/utils.bal b/ballerina/modules/bulk/tests/utils.bal index 84d46b9e..9753a941 100644 --- a/ballerina/modules/bulk/tests/utils.bal +++ b/ballerina/modules/bulk/tests/utils.bal @@ -24,7 +24,7 @@ json[] jsonInsertResult = []; xml xmlInsertResult = xml ``; string csvInputResult = "Id"; -// Create Salesforce client configuration by reading from environemnt. +// Create Salesforce client configuration by reading from environment. configurable string clientId = os:getEnv("CLIENT_ID"); configurable string clientSecret = os:getEnv("CLIENT_SECRET"); configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); diff --git a/ballerina/tests/bulk_csv_insert.bal b/ballerina/tests/bulk_csv_insert.bal index 75295d44..796778bf 100644 --- a/ballerina/tests/bulk_csv_insert.bal +++ b/ballerina/tests/bulk_csv_insert.bal @@ -95,7 +95,7 @@ function insertCsv() returns error? { } function insertCsvFromFile() returns error? { log:printInfo("baseClient -> insertCsvFromFile"); - string csvContactsFilePath = "ballerina/tests/resources/contacts1.csv"; + string csvContactsFilePath = "tests/resources/contacts1.csv"; //create job BulkCreatePayload payload = { @@ -158,7 +158,7 @@ function insertCsvFromFile() returns error? { function insertCsvStringArrayFromFile() returns error? { log:printInfo("baseClient -> insertCsvStringArrayFromFile"); - string csvContactsFilePath = "ballerina/tests/resources/contacts2.csv"; + string csvContactsFilePath = "tests/resources/contacts2.csv"; //create job BulkCreatePayload payload = { @@ -226,7 +226,7 @@ function insertCsvStringArrayFromFile() returns error? { function insertCsvStreamFromFile() returns error? { log:printInfo("baseClient -> insertCsvStreamFromFile"); - string csvContactsFilePath = "ballerina/tests/resources/contacts3.csv"; + string csvContactsFilePath = "tests/resources/contacts3.csv"; stream csvStream = check io:fileReadCsvAsStream(csvContactsFilePath); //create job diff --git a/examples/apex_rest_api_usecases/create_case/Ballerina.toml b/examples/apex_rest_api_usecases/create_case/Ballerina.toml new file mode 100644 index 00000000..37090d1f --- /dev/null +++ b/examples/apex_rest_api_usecases/create_case/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_apex_rest" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/apex_rest_api_usecases/create_case/README.md b/examples/apex_rest_api_usecases/create_case/README.md new file mode 100644 index 00000000..34436731 --- /dev/null +++ b/examples/apex_rest_api_usecases/create_case/README.md @@ -0,0 +1,28 @@ +# Use APEX REST API + +This example demonstrates how to invoke APEX REST API of Salesforce. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/apex_rest_api_usecases/invoke_apex_methods.bal b/examples/apex_rest_api_usecases/create_case/invoke_apex_methods.bal similarity index 79% rename from samples/apex_rest_api_usecases/invoke_apex_methods.bal rename to examples/apex_rest_api_usecases/create_case/invoke_apex_methods.bal index 1a0dda4b..5467222c 100644 --- a/samples/apex_rest_api_usecases/invoke_apex_methods.bal +++ b/examples/apex_rest_api_usecases/create_case/invoke_apex_methods.bal @@ -16,15 +16,14 @@ import ballerina/log; import ballerinax/salesforce; -import ballerina/os; import ballerina/lang.runtime; -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); +// Create Salesforce client configuration by reading from environment. +configurable string clientId = ?; +configurable string clientSecret = ?; +configurable string refreshToken = ?; +configurable string refreshUrl = ?; +configurable string baseUrl = ?; // Using direct-token config for client configuration salesforce:ConnectionConfig sfConfig = { @@ -42,10 +41,9 @@ public function main() returns error? { salesforce:Client baseClient = check new (sfConfig); string|error caseId = baseClient->apexRestExecute("Cases", "POST", - {"subject" : "Bigfoot Sighting9!", + {"subject" : "Item Fault!", "status" : "New", - "origin" : "Phone", - "priority" : "Low"}); + "priority" : "High"}); if caseId is error { log:printError("Error occurred while creating the case. "); return; diff --git a/samples/build.gradle b/examples/build.gradle similarity index 69% rename from samples/build.gradle rename to examples/build.gradle index 2ae673bc..aa346e8a 100644 --- a/samples/build.gradle +++ b/examples/build.gradle @@ -16,8 +16,9 @@ * under the License. */ +import org.apache.tools.ant.taskdefs.condition.Os -apply plugin: 'java-library' +apply plugin: 'java' description = 'Ballerina - Salesforce Test samples' @@ -46,8 +47,20 @@ task buildExamples { } } doLast { - // Enabled --offline due to a bug in pulling incorrect versions from the central repository. - examples.each { example -> executeBalCommand ("build --offline ${example}", "${project.rootDir}") } + try { + exec { + workingDir project.projectDir + println("Working dir: ${workingDir}") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'sh', "/c", "chmod +x ./build.sh && ./build.sh build && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh build" + } + } + } catch (Exception e) { + println("Example Build failed: " + e.message) + throw e + } } } diff --git a/examples/build.sh b/examples/build.sh new file mode 100755 index 00000000..1c283320 --- /dev/null +++ b/examples/build.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io/" +BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina" + +set -e + +case "$1" in +build) + BAL_CMD="build" + ;; +run) + BAL_CMD="run" + ;; +*) + echo "Invalid command provided: '$1'. Please provide 'build' or 'test' as the command." + exit 1 + ;; +esac + +# Read Ballerina package name +BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml") + +# Push the package to the local repository +cd "$BAL_HOME_DIR" && + bal pack && + bal push --repository=local + +# Remove the cache directories in the repositories +cacheDirs=($(ls -d "$BAL_CENTRAL_DIR"/cache-* 2>/dev/null)) +for dir in "${cacheDirs[@]}"; do + [ -d "$dir" ] && rm -r "$dir" +done +echo "Successfully cleaned the cache directories" + +# Update the central repository +BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME" +BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME" +[ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR" +[ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR" +echo "Successfully updated the local central repositories" + + +# Loop through examples in the examples directory +cd "$BAL_EXAMPLES_DIR" +for dir in $(find "$BAL_EXAMPLES_DIR" -type d -maxdepth 2 -mindepth 2); do + # Skip the build directory + if [[ "$dir" == *libs ]] || [[ "$dir" == *tmp ]]; then + continue + fi + (cd "$dir" && bal "$BAL_CMD" --offline && cd ..); +done + diff --git a/examples/bulk_api_usecases/execute_delete_job/Ballerina.toml b/examples/bulk_api_usecases/execute_delete_job/Ballerina.toml new file mode 100644 index 00000000..101357e9 --- /dev/null +++ b/examples/bulk_api_usecases/execute_delete_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_bulk_delete" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulk_api_usecases/execute_delete_job/README.md b/examples/bulk_api_usecases/execute_delete_job/README.md new file mode 100644 index 00000000..c1bb6fdd --- /dev/null +++ b/examples/bulk_api_usecases/execute_delete_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk API + +This example demonstrates how to invoke delete operation using bulk API. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_delete_csv.bal b/examples/bulk_api_usecases/execute_delete_job/bulk_delete_csv.bal similarity index 93% rename from samples/bulk_api_usecases/bulk-operations-csv/bulk_delete_csv.bal rename to examples/bulk_api_usecases/execute_delete_job/bulk_delete_csv.bal index 5a2bf16e..2a0655ed 100644 --- a/samples/bulk_api_usecases/bulk-operations-csv/bulk_delete_csv.bal +++ b/examples/bulk_api_usecases/execute_delete_job/bulk_delete_csv.bal @@ -17,14 +17,13 @@ import ballerina/log; import ballerinax/salesforce.bulk; import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); + +// Create Salesforce client configuration by reading from environment. +configurable string clientId = ?; +configurable string clientSecret = ?; +configurable string refreshToken = ?; +configurable string refreshUrl = ?; +configurable string baseUrl = ?; // Using direct-token config for client configuration bulk:ConnectionConfig sfConfig = { diff --git a/examples/bulk_api_usecases/execute_insert_job/Ballerina.toml b/examples/bulk_api_usecases/execute_insert_job/Ballerina.toml new file mode 100644 index 00000000..60c9dbfd --- /dev/null +++ b/examples/bulk_api_usecases/execute_insert_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_bulk_insert" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulk_api_usecases/execute_insert_job/README.md b/examples/bulk_api_usecases/execute_insert_job/README.md new file mode 100644 index 00000000..90cbf42b --- /dev/null +++ b/examples/bulk_api_usecases/execute_insert_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk API + +This example demonstrates how to invoke insert operation using bulk API. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_insert_csv.bal b/examples/bulk_api_usecases/execute_insert_job/bulk_insert_csv.bal similarity index 100% rename from samples/bulk_api_usecases/bulk-operations-csv/bulk_insert_csv.bal rename to examples/bulk_api_usecases/execute_insert_job/bulk_insert_csv.bal diff --git a/examples/bulk_api_usecases/execute_query_job/Ballerina.toml b/examples/bulk_api_usecases/execute_query_job/Ballerina.toml new file mode 100644 index 00000000..7538ae34 --- /dev/null +++ b/examples/bulk_api_usecases/execute_query_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_bulk_query" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulk_api_usecases/execute_query_job/README.md b/examples/bulk_api_usecases/execute_query_job/README.md new file mode 100644 index 00000000..d3282042 --- /dev/null +++ b/examples/bulk_api_usecases/execute_query_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk API + +This example demonstrates how to invoke query operation using bulk API. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_query_csv.bal b/examples/bulk_api_usecases/execute_query_job/bulk_query_csv.bal similarity index 100% rename from samples/bulk_api_usecases/bulk-operations-csv/bulk_query_csv.bal rename to examples/bulk_api_usecases/execute_query_job/bulk_query_csv.bal diff --git a/examples/bulk_api_usecases/execute_update_job/Ballerina.toml b/examples/bulk_api_usecases/execute_update_job/Ballerina.toml new file mode 100644 index 00000000..c74e693e --- /dev/null +++ b/examples/bulk_api_usecases/execute_update_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_bulk_update" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulk_api_usecases/execute_update_job/README.md b/examples/bulk_api_usecases/execute_update_job/README.md new file mode 100644 index 00000000..9999d3f2 --- /dev/null +++ b/examples/bulk_api_usecases/execute_update_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk API + +This example demonstrates how to invoke update operation using bulk API. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_update_csv.bal b/examples/bulk_api_usecases/execute_update_job/bulk_update_csv.bal similarity index 100% rename from samples/bulk_api_usecases/bulk-operations-csv/bulk_update_csv.bal rename to examples/bulk_api_usecases/execute_update_job/bulk_update_csv.bal diff --git a/examples/bulk_api_usecases/execute_upsert_job/Ballerina.toml b/examples/bulk_api_usecases/execute_upsert_job/Ballerina.toml new file mode 100644 index 00000000..3ff5dd70 --- /dev/null +++ b/examples/bulk_api_usecases/execute_upsert_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_bulk_upsert" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulk_api_usecases/execute_upsert_job/README.md b/examples/bulk_api_usecases/execute_upsert_job/README.md new file mode 100644 index 00000000..32d1166c --- /dev/null +++ b/examples/bulk_api_usecases/execute_upsert_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk API + +This example demonstrates how to invoke upsert operation using bulk API. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_upsert_csv.bal b/examples/bulk_api_usecases/execute_upsert_job/bulk_upsert_csv.bal similarity index 100% rename from samples/bulk_api_usecases/bulk-operations-csv/bulk_upsert_csv.bal rename to examples/bulk_api_usecases/execute_upsert_job/bulk_upsert_csv.bal diff --git a/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/Ballerina.toml b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/Ballerina.toml new file mode 100644 index 00000000..37090d1f --- /dev/null +++ b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_apex_rest" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/README.md b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/README.md new file mode 100644 index 00000000..1bdbbe1d --- /dev/null +++ b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/README.md @@ -0,0 +1,28 @@ +# Use Bulk V2 API + +This example demonstrates how to invoke Bulk API v2 of Salesforce. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/bulkv2_api_usecases/bulkv2_insert.bal b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/bulkv2_insert.bal similarity index 89% rename from samples/bulkv2_api_usecases/bulkv2_insert.bal rename to examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/bulkv2_insert.bal index 341034b1..1c1d9fe3 100644 --- a/samples/bulkv2_api_usecases/bulkv2_insert.bal +++ b/examples/bulkv2_api_usecases/execute_bulkv2_ingest_job/bulkv2_insert.bal @@ -15,16 +15,15 @@ // under the License. import ballerinax/salesforce; -import ballerina/os; import ballerina/lang.runtime; import ballerina/io; -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); +// Create Salesforce client configuration by reading from environment. +configurable string clientId = ?; +configurable string clientSecret = ?; +configurable string refreshToken = ?; +configurable string refreshUrl = ?; +configurable string baseUrl = ?; // Using direct-token config for client configuration salesforce:ConnectionConfig sfConfig = { diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/.devcontainer.json b/examples/ftp-edi-message-to-salesforce-opportunity/.devcontainer.json deleted file mode 100644 index 6269c065..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/.devcontainer.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "image": "ballerina/ballerina-devcontainer:2201.7.0", - "extensions": ["WSO2.ballerina"], -} diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/.gitignore b/examples/ftp-edi-message-to-salesforce-opportunity/.gitignore deleted file mode 100644 index d0bbdca4..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -generated -Config.toml -test_input diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/Ballerina.toml b/examples/ftp-edi-message-to-salesforce-opportunity/Ballerina.toml deleted file mode 100644 index 9cce1c5c..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "salesforce_examples" -name = "ftp_edi_message_to_salesforce_opportunity" -version = "0.1.0" -distribution = "2201.7.0" - -[build-options] -observabilityIncluded = true diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/README.md b/examples/ftp-edi-message-to-salesforce-opportunity/README.md deleted file mode 100644 index dec92a6b..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# FTP B2B EDI message to Salesforce opportunity - -This sample reads EDI files from a given FTP location, converts those EDI messages to Ballerina records, and creates a Salesforce opportunity for each EDI message. - -## Use case - -Business-to-Business(B2B) communications are commonly performed via EDI messages. Therefore, it's critical to integrate B2B messaging channels with internal IT to streamline and automate business processes. In this context, this sample shows how EDI messages containing requests for quotes (EDIFACT REQOTE) can be used to automatically create opportunities in Salesforce, and add all products in a quote as products associated with the opportunity. - -## Prerequisites -* Salesforce account -* FTP server - -### Setting up the Salesforce account -1. Visit [Salesforce](https://www.salesforce.com/) and create a Salesforce Account. -2. Create a connected app and obtain the following credentials: - * Base URL (Endpoint) - * Access Token - * Client ID - * Client Secret - * Refresh Token - * Refresh Token URL -3. When you are setting up the connected app, select the following scopes under Selected OAuth Scopes: - * Access and manage your data (api) - * Perform requests on your behalf at any time (refresh_token, offline_access) - * Provide access to your data via the Web (web) -4. Provide the client ID and client secret to obtain the refresh token and access token. For more information on obtaining OAuth2 credentials, go to [Salesforce documentation](https://help.salesforce.com/articleView?id=remoteaccess_authenticate_overview.htm). -5. Fill in details under the `Salesforce configuration` in the `Config.toml` with Salesforce access details. -6. Create a sample Account named `TechShop` in Salesforce. -7. Create two Products in Salesforce and obtain product IDs. Replace `` and `` place holders in `resoures/inputs/quote1.edi` and `resources/inputs/quote2.edi` with product IDs. -8. Create a PriceBook in Salesforce and fill the `salesforcePriceBookId` entry in `Config.toml` with the price book ID. Add prices for products created in step 7 to the price book. - -### Setting up an FTP server -1. Start FTP server using the command below. -```docker run -d -p :21 -p 21000-21010:21000-21010 -e USERS="|" -e ADDRESS=localhost delfer/alpine-ftp-server``` -(E.g. ```docker run -d -p 2100:21 -p 21000-21010:21000-21010 -e USERS="user1|pass1" -e ADDRESS=localhost delfer/alpine-ftp-server```). -Note that any FTP server with read and write access can be used for this sample. If an FTP server is available, skip this point. -2. Create two folders in the FTP server for input EDI files and processed EDI files (E.g. `samples/new-quotes`, `samples/processed-quotes`) -3. Copy files in the resources/inputs folder to the FTP folder created for input EDI files. -4. Fill in fields under the `FTP configuration` section in `Config.toml` with FTP server details and paths for EDI files. - -### Config.toml -``` -salesforcePriceBookId = "" -ftpNewQuotesPath = "" -ftpProcessedQuotesPath = "" - -# ========================== -# FTP configuration -# ========================== - -[ftpConfig] -protocol = "ftp" -host = "localhost" -port = - -[ftpConfig.auth.credentials] -username = "" -password = "" - -# ========================== -# Salesforce configuration -# ========================== - -[salesforceConfig] -baseUrl = "" - -[salesforceConfig.auth] -clientId = "" -clientSecret = "" -refreshToken = "" -refreshUrl = "" -``` - -## Testing - -1. Make sure the FTP server is running. -2. Run the sample using the `bal run` command. -3. Log in to Salesforce and check opportunities. Two new opportunities will be created, one for each EDI file. -4. Check FTP locations. Both EDI files will be moved to the process-quotes folder. - diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/main.bal b/examples/ftp-edi-message-to-salesforce-opportunity/main.bal deleted file mode 100644 index 1739defb..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/main.bal +++ /dev/null @@ -1,120 +0,0 @@ -import ballerina/ftp; -import ballerina/io; -import ballerinax/edifact.d03a.retail.mREQOTE; -import ballerinax/salesforce as sf; -configurable ftp:ClientConfiguration ftpConfig = ?; -configurable string ftpNewQuotesPath = ?; -configurable string ftpProcessedQuotesPath = ?; -configurable sf:ConnectionConfig salesforceConfig = ?; -configurable string salesforcePriceBookId = ?; -sf:Client salesforce = check new (salesforceConfig); -ftp:Client fileServer = check new ftp:Client(ftpConfig); -public function main() returns error? { - ftp:FileInfo[] quoteList = check fileServer->list(ftpNewQuotesPath); - foreach ftp:FileInfo quoteFile in quoteList { - stream fileStream = check fileServer->get(quoteFile.path); - string quoteText = check streamToString(fileStream); - mREQOTE:EDI_REQOTE_Request_for_quote_message quote = check mREQOTE:fromEdiString(quoteText); - QuoteRequest quoteRequest = check transformQuoteRequest(quote); - stream accQuery = check salesforce->query( - string `SELECT Id FROM Account WHERE Name = '${quoteRequest.accountName}'` - ); - record {|Id value;|}? account = check accQuery.next(); - check accQuery.close(); - if account is () { - return error("Account not found. Account name: " + quoteRequest.accountName); - } - Opportunity opp = { - Name: quoteRequest.oppName, - AccountId: account.value.Id, - Pricebook2Id: salesforcePriceBookId - }; - string oppId = check getOpportunityId(salesforce, quoteRequest, opp); - check createOpportunityLineItems(quoteRequest, oppId); - } -} -function createOpportunityLineItems(QuoteRequest quoteRequest, string oppId) returns error? { - foreach ItemData item in quoteRequest.itemData { - stream query = check salesforce->query( - string `SELECT UnitPrice FROM PricebookEntry WHERE Pricebook2Id = - '01s6C000000UN4PQAW' AND Product2Id = '${item.itemId}'` - ); - record {|PriceBookEntry value;|}? unionResult = check query.next(); - check query.close(); - if unionResult is () { - return error(string `Pricebook entry not found. Opportunity name: ${quoteRequest.oppName}, Item ID: ${item.itemId}`); - } - OpportunityProduct oppProduct = { - OpportunityId: oppId, - Product2Id: item.itemId, - Quantity: item.quantity, - UnitPrice: unionResult.value.UnitPrice - }; - _ = check salesforce->create("OpportunityLineItem", oppProduct); - } -} -function getOpportunityId(sf:Client salesforce, QuoteRequest quoteRequest, Opportunity opp) returns string|error { - string oppId = ""; - stream oppQuery = check salesforce->query( - string `SELECT Id FROM Opportunity WHERE Name = '${quoteRequest.oppName}'`); - record {|Id value;|}? existingOpp = check oppQuery.next(); - check oppQuery.close(); - if existingOpp is () { - sf:CreationResponse oppResult = check salesforce->create("Opportunity", opp); - oppId = oppResult.id; - } else { - oppId = existingOpp.value.Id; - } - return oppId; -} -function transformQuoteRequest(mREQOTE:EDI_REQOTE_Request_for_quote_message quote) returns QuoteRequest|error { - QuoteRequest quoteRequest = {accountName: "", oppName: ""}; - mREQOTE:Segment_group_1_GType[] segmentGroup1 = quote.Segment_group_1; - foreach mREQOTE:Segment_group_1_GType ref in segmentGroup1 { - if ref.REFERENCE.REFERENCE.Reference_code_qualifier == "AES" { - string? oppId = ref.REFERENCE.REFERENCE.Reference_identifier; - if oppId is () { - return error("Opportunity ID is not given"); - } - quoteRequest.oppName = oppId; - } - } - mREQOTE:Segment_group_11_GType[] segmentGroup11 = quote.Segment_group_11; - foreach mREQOTE:Segment_group_11_GType party in segmentGroup11 { - if party.NAME_AND_ADDRESS.Party_function_code_qualifier == "BY" { - string? prospectId = party.NAME_AND_ADDRESS?.PARTY_IDENTIFICATION_DETAILS?.Party_identifier; - if prospectId is () { - return error("Prospect identifier not available in quote."); - } - quoteRequest.accountName = prospectId; - } - } - mREQOTE:Segment_group_27_GType[] items = quote.Segment_group_27; - foreach mREQOTE:Segment_group_27_GType item in items { - string? itemId = item.LINE_ITEM.Line_item_identifier; - if itemId is () { - return error("Item ID is not given"); - } - ItemData itemData = {itemId}; - mREQOTE:QUANTITY_Type[] quantities = item.QUANTITY; - foreach mREQOTE:QUANTITY_Type quantity in quantities { - if quantity.QUANTITY_DETAILS.Quantity_type_code_qualifier == "21" { - int|error amount = int:fromString(quantity.QUANTITY_DETAILS.Quantity); - if amount is error { - return error("Quantity must be a valid number."); - } - itemData.quantity = amount; - break; - } - } - quoteRequest.itemData.push(itemData); - } - return quoteRequest; -} -function streamToString(stream inStream) returns string|error { - byte[] content = []; - check inStream.forEach(function(byte[] & readonly chunk) { - content.push(...chunk); - }); - return string:fromBytes(content); -} \ No newline at end of file diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote1.edi b/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote1.edi deleted file mode 100644 index 24bf9064..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote1.edi +++ /dev/null @@ -1,8 +0,0 @@ -BGM+930+1001' -DTM+137:20230815:102' -RFF+AES:TS_035' -NAD+BY+TechShop' -LIN+' -QTY+21:10' -UNS+S' -UNT+8+1' diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote2.edi b/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote2.edi deleted file mode 100644 index 662ce9ab..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/resources/inputs/quote2.edi +++ /dev/null @@ -1,10 +0,0 @@ -BGM+930+1002' -DTM+137:20230819:102' -RFF+AES:TS_015' -NAD+BY+TechShop' -LIN+' -QTY+21:25' -LIN+' -QTY+21:18' -UNS+S' -UNT+8+1' diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/transformer.bal b/examples/ftp-edi-message-to-salesforce-opportunity/transformer.bal deleted file mode 100644 index 204fcaeb..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/transformer.bal +++ /dev/null @@ -1,45 +0,0 @@ -import ballerinax/edifact.d03a.retail.mREQOTE; -function transformQuoteRequest(mREQOTE:EDI_REQOTE_Request_for_quote_message quote) returns QuoteRequest|error { - QuoteRequest quoteRequest = {accountName: "", oppName: ""}; - mREQOTE:Segment_group_1_GType[] segmentGroup1 = quote.Segment_group_1; - foreach mREQOTE:Segment_group_1_GType ref in segmentGroup1 { - if ref.REFERENCE.REFERENCE.Reference_code_qualifier == "AES" { - string? oppId = ref.REFERENCE.REFERENCE.Reference_identifier; - if oppId is () { - return error("Opportunity ID is not given"); - } - quoteRequest.oppName = oppId; - } - } - mREQOTE:Segment_group_11_GType[] segmentGroup11 = quote.Segment_group_11; - foreach mREQOTE:Segment_group_11_GType party in segmentGroup11 { - if party.NAME_AND_ADDRESS.Party_function_code_qualifier == "BY" { - string? prospectId = party.NAME_AND_ADDRESS?.PARTY_IDENTIFICATION_DETAILS?.Party_identifier; - if prospectId is () { - return error("Prospect identifier not available in quote."); - } - quoteRequest.accountName = prospectId; - } - } - mREQOTE:Segment_group_27_GType[] items = quote.Segment_group_27; - foreach mREQOTE:Segment_group_27_GType item in items { - string? itemId = item.LINE_ITEM.Line_item_identifier; - if itemId is () { - return error("Item ID is not given"); - } - ItemData itemData = {itemId}; - mREQOTE:QUANTITY_Type[] quantities = item.QUANTITY; - foreach mREQOTE:QUANTITY_Type quantity in quantities { - if quantity.QUANTITY_DETAILS.Quantity_type_code_qualifier == "21" { - int|error amount = int:fromString(quantity.QUANTITY_DETAILS.Quantity); - if amount is error { - return error("Quantity must be a valid number."); - } - itemData.quantity = amount; - break; - } - } - quoteRequest.itemData.push(itemData); - } - return quoteRequest; -} \ No newline at end of file diff --git a/examples/ftp-edi-message-to-salesforce-opportunity/types.bal b/examples/ftp-edi-message-to-salesforce-opportunity/types.bal deleted file mode 100644 index 8d2b9eef..00000000 --- a/examples/ftp-edi-message-to-salesforce-opportunity/types.bal +++ /dev/null @@ -1,39 +0,0 @@ -type QuoteRequest record {| - string oppName; - string accountName; - ItemData[] itemData = []; -|}; - -type ItemData record {| - string itemId; - int quantity = 0; -|}; - -type Id record {| - string Id; -|}; - -type PriceBookEntry record {| - decimal UnitPrice; -|}; - -type OpportunityProduct record {| - string OpportunityId; - string Working_with_3rd_party__c = "No"; - string Product2Id; - int Quantity; - decimal UnitPrice; -|}; - -type Opportunity record {| - string Name; - string CurrencyIsoCode = "USD"; - string LeadSource = "Customer Inbound"; - string AccountId; - string ForecastCategoryName = "Pipeline"; - string CloseDate = "2023-12-18"; - string StageName = "40 - Negotiation/Review"; - string Confidence__c = "Low"; - string Pricebook2Id = "01s6C000000UN4PQAW"; - string Working_with_3rd_party__c = "No"; -|}; diff --git a/examples/gmail-to-salesforce-lead/.gitignore b/examples/gmail-to-salesforce-lead/.gitignore deleted file mode 100644 index 7512ebe2..00000000 --- a/examples/gmail-to-salesforce-lead/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -generated -Config.toml diff --git a/examples/gmail-to-salesforce-lead/Ballerina.toml b/examples/gmail-to-salesforce-lead/Ballerina.toml deleted file mode 100644 index 5995c893..00000000 --- a/examples/gmail-to-salesforce-lead/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "salesforce_examples" -name = "gmail_to_salesforce_lead" -version = "0.1.0" -distribution = "2201.7.0" - -[build-options] -observabilityIncluded = true diff --git a/examples/gmail-to-salesforce-lead/Dependencies.toml b/examples/gmail-to-salesforce-lead/Dependencies.toml deleted file mode 100644 index 4598e5a0..00000000 --- a/examples/gmail-to-salesforce-lead/Dependencies.toml +++ /dev/null @@ -1,410 +0,0 @@ -# AUTO-GENERATED FILE. DO NOT MODIFY. - -# This file is auto-generated by Ballerina for managing dependency versions. -# It should not be modified by hand. - -[ballerina] -dependencies-toml-version = "2" -distribution-version = "2201.7.1" - -[[package]] -org = "ballerina" -name = "auth" -version = "2.9.0" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"} -] - -[[package]] -org = "ballerina" -name = "cache" -version = "3.6.0" -dependencies = [ - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "constraint" -version = "1.3.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "crypto" -version = "2.4.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "file" -version = "1.8.1" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "os"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "http" -version = "2.9.2" -dependencies = [ - {org = "ballerina", name = "auth"}, - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "file"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "jwt"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.decimal"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.regexp"}, - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "mime"}, - {org = "ballerina", name = "oauth2"}, - {org = "ballerina", name = "observe"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "url"} -] - -[[package]] -org = "ballerina" -name = "io" -version = "1.5.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] - -[[package]] -org = "ballerina" -name = "jballerina.java" -version = "0.0.0" - -[[package]] -org = "ballerina" -name = "jwt" -version = "2.9.0" -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.boolean" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.decimal" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.float" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.int" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" - -[[package]] -org = "ballerina" -name = "lang.regexp" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.runtime" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"} -] - -[[package]] -org = "ballerina" -name = "lang.string" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.regexp"} -] - -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.xml" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "log" -version = "2.8.1" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "observe"} -] -modules = [ - {org = "ballerina", packageName = "log", moduleName = "log"} -] - -[[package]] -org = "ballerina" -name = "mime" -version = "2.8.0" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"} -] -modules = [ - {org = "ballerina", packageName = "mime", moduleName = "mime"} -] - -[[package]] -org = "ballerina" -name = "oauth2" -version = "2.9.0" -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "url"} -] - -[[package]] -org = "ballerina" -name = "observe" -version = "1.1.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "os" -version = "1.7.0" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "regex" -version = "1.4.3" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.string"} -] - -[[package]] -org = "ballerina" -name = "task" -version = "2.4.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "time" -version = "2.3.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "url" -version = "2.3.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerinai" -name = "observe" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "observe"} -] -modules = [ - {org = "ballerinai", packageName = "observe", moduleName = "observe"} -] - -[[package]] -org = "ballerinax" -name = "client.config" -version = "1.0.1" -dependencies = [ - {org = "ballerina", name = "http"}, - {org = "ballerina", name = "oauth2"} -] - -[[package]] -org = "ballerinax" -name = "googleapis.gmail" -version = "3.5.0" -dependencies = [ - {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "mime"}, - {org = "ballerina", name = "os"}, - {org = "ballerina", name = "regex"}, - {org = "ballerina", name = "url"}, - {org = "ballerinai", name = "observe"}, - {org = "ballerinax", name = "client.config"} -] -modules = [ - {org = "ballerinax", packageName = "googleapis.gmail", moduleName = "googleapis.gmail"} -] - -[[package]] -org = "ballerinax" -name = "openai.chat" -version = "1.1.2" -dependencies = [ - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "http"}, - {org = "ballerina", name = "url"}, - {org = "ballerinai", name = "observe"} -] -modules = [ - {org = "ballerinax", packageName = "openai.chat", moduleName = "openai.chat"} -] - -[[package]] -org = "ballerinax" -name = "salesforce" -version = "7.5.1" -dependencies = [ - {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.boolean"}, - {org = "ballerina", name = "lang.float"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "lang.xml"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "os"}, - {org = "ballerina", name = "regex"}, - {org = "ballerina", name = "url"}, - {org = "ballerinai", name = "observe"}, - {org = "ballerinax", name = "client.config"} -] -modules = [ - {org = "ballerinax", packageName = "salesforce", moduleName = "salesforce"}, - {org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.bulk"}, - {org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.soap"}, - {org = "ballerinax", packageName = "salesforce", moduleName = "salesforce.utils"} -] - -[[package]] -org = "integration_samples" -name = "gmail_to_salesforce_lead" -version = "0.1.0" -dependencies = [ - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "mime"}, - {org = "ballerinai", name = "observe"}, - {org = "ballerinax", name = "googleapis.gmail"}, - {org = "ballerinax", name = "openai.chat"}, - {org = "ballerinax", name = "salesforce"} -] -modules = [ - {org = "integration_samples", packageName = "gmail_to_salesforce_lead", moduleName = "gmail_to_salesforce_lead"} -] - diff --git a/examples/gmail-to-salesforce-lead/README.md b/examples/gmail-to-salesforce-lead/README.md deleted file mode 100644 index ceee3ecf..00000000 --- a/examples/gmail-to-salesforce-lead/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# Email Lead Info into Salesforce using OpenAI. -This sample creates a lead on [Salesforce](https://salesforce.com) for each email marked with a specific label on [Gmail](https://mail.google.com) using the [OpenAI](https://openai.com) chat API to infer customer details. - -## Use case -The following sample demonstrates a scenario in which customer leads obtained through email are automatically pushed to Salesforce. The required details for the lead (name, company, designation, etc.) are inferred from the content of the email and the OpenAI chat API. - -When the user receives an email pertaining to a lead, they will mark that thread with a specific label (e.g., `"Lead"`). This Ballerina program will run continuously in the background, polling the email server every 10 minutes for threads marked with this label. If an email is found, its content will be read and used to infer the following details -* First name -* Last name -* Phone number -* Email address -* Company name -* Designation - -Once these details have been inferred, a new lead will be generated on Salesforce. - -![Flow diagram](/gmail-to-salesforce-lead/docs/images/flow-diagram.png) - -## Prerequisites -* An email account configured to use [Gmail](https://mail.google.com) -* An account on the [Google Cloud Platform](https://console.cloud.google.com) -* An [OpenAI](https://openai.com) account with API usage enabled -* A [Salesforce](https://salesforce.com) account - ->Note: The following steps will require you to generate keys for the Gmail, OpenAI and Salesforce APIs. These keys will have to be securely stored in the `Config.toml` file in the project directory under the relevant fields. - -### Configuring your email account to use Gmail -> Note: If you already have a Gmail account (ending with `@gmail.com`) or your account is on the Google workspace, you do not need to follow the steps below. In essence, if you can access your email via `www.gmail.com`, the following is not necessary. -1. Visit [Gmail](https://gmail.com) and create a new account or log into an existing account. -2. Enter the `Accounts` tab under settings and click on `Add a mail account`. -3. Provide the necessary authentication details to your email account. -4. After adding a mail account, you should be able to see all new emails received to your email via the Gmail interface. - -### Obtaining the Gmail API keys -1. Create a new [Google Cloud Platform project](https://console.cloud.google.com). -2. Find and click `APIs & Services` --> `Library` from the navigation menu. -3. In the search box, enter `"Gmail"`. -4. Then select Gmail API and click `Enable` button. -5. Complete the OAuth consent screen setup. -6. Click the `Credential` tab from the left sidebar. In the displaying window click on the `Create Credentials` button and select OAuth client ID. -7. Fill in the required fields. Add `"https://developers.google.com/oauthplayground"` to the Redirect URI field. -8. Note down the `clientId` and `clientSecret`. -9. Visit https://developers.google.com/oauthplayground/. Go to settings (Top right corner) -> Tick 'Use your own OAuth credentials' and insert Oauth ClientId and clientSecret. Click close. -10. Then, Complete Step1 (Select and Authorize APIs) -11. Make sure you select the `"https://www.googleapis/auth/gmail.modify"` and `"https://www.googleapis/auth/gmail.labels` OAuth scopes. These two scopes will allow the program to read emails, including adding/removing labels. -12. Click `Authorize APIs`, and you will be in step 2. -13. Exchange Auth code for tokens. -14. Copy the `Access token` and enter it on the `Config.toml` file. - -### Obtaining an OpenAI key -1. Create an [OpenAI account](https://platform.openai.com). -2. If you are eligible for a free trial of the OpenAI API, use that. Otherwise, set up your [billing information](https://platform.openai.com/account/billing/overview). -3. Obtain your [API key](https://platform.openai.com/account/api-keys) and include it in the `Config.toml` file. - -### Setting up the Salesforce account -1. Visit [Salesforce](https://www.salesforce.com/) and create a Salesforce account. -2. Create a connected app and obtain the following credentials: - * Base URL (Endpoint) - * Client ID - * Client Secret - * Refresh Token - * Refresh Token URL -3. When you are setting up the connected app, select the following scopes under Selected OAuth Scopes: - * Access and manage your data (api) - * Perform requests on your behalf at any time (refresh_token, offline_access) - * Provide access to your data via the Web (web) -4. Provide the client ID and client secret to obtain the refresh token and access token. For more information on obtaining OAuth2 credentials, go to [Salesforce documentation](https://help.salesforce.com/articleView?id=remoteaccess_authenticate_overview.htm). -5. Once you have obtained the access token, include it in the `Config.toml` file. - -## Configuration -Create a file called `Config.toml` at the root of the project. - -### Config.toml -``` -gmailAccessToken = "" -openAIKey = "" -salesforceBaseUrl = "https://.salesforce.com" -salesforceAccessToken = "" -``` -### Configuration -1. Obtain the relevant OAuth access tokens for `Google Drive` and `Microsoft One Drive` configurations. -2. Obtain the folder ID of the Google Drive folder you want to sync. -3. Obtain the path of the OneDrive folder you want to sync. -4. Once you have obtained all configurations, Create the `Config.toml` file in the root directory. -5. Replace the necessary fields in the `Config.toml` file with your data. - -## Testing - -### Adding labels -In Gmail, we can use a label to mark an email under several categories. These labels can be manually added to email threads by the user or can be automatically added based on user-provided rules as well. For this sample, we will use a custom label to mark emails pertaining to a lead generation as `"Lead"`. - -1. Log into your Gmail account. -2. Create a new label named `"Lead"` from the `Labels` tab under `Settings` -3. Whenever you receive an email pertaining to a lead generation, add the newly created label to it by clicking on the Labels icon above the thread. - -### Running the project -1. Execute the ballerina project by executing `bal run` in the project directory. -2. You should see the emails you've marked as `LEAD` should have the label removed and a new lead should be created on Salesforce. diff --git a/examples/gmail-to-salesforce-lead/docs/images/flow-diagram.png b/examples/gmail-to-salesforce-lead/docs/images/flow-diagram.png deleted file mode 100644 index 9a72de95..00000000 Binary files a/examples/gmail-to-salesforce-lead/docs/images/flow-diagram.png and /dev/null differ diff --git a/examples/gmail-to-salesforce-lead/main.bal b/examples/gmail-to-salesforce-lead/main.bal deleted file mode 100644 index f935adbd..00000000 --- a/examples/gmail-to-salesforce-lead/main.bal +++ /dev/null @@ -1,85 +0,0 @@ -import ballerina/mime; -import ballerinax/googleapis.gmail; -import ballerinax/openai.chat; -import ballerinax/salesforce as sf; - -configurable string gmailAccessToken = ?; -configurable string openAIKey = ?; -configurable string salesforceBaseUrl = ?; -configurable string salesforceAccessToken = ?; - -gmail:Client gmail = check new ({auth: {token: gmailAccessToken}}); -chat:Client openAiChat = check new ({auth: {token: openAIKey}}); -sf:Client salesforce = check new ({baseUrl: salesforceBaseUrl, auth: {token: salesforceAccessToken}}); - -public function main() returns error? { - gmail:LabelList labelList = check gmail->listLabels("me"); - Email[] emails = check getMatchingEmails(labelList); - foreach Email email in emails { - chat:CreateChatCompletionRequest request = { - model: "gpt-3.5-turbo", - messages: [ - { - role: "user", - content: string `Extract the following details in JSON from the email. - { - firstName__c: string, // Mandatory - lastName__c: string, // Mandatory - email__c: string // Mandatory - phoneNumber__c: string, // With country code. Use N/A if unable to find - company__c: string, // Mandatory - designation__c: string // Not mandatory. Use N/A if unable to find - } - Here is the email: - { - from: ${email.'from}, - subject: ${email.subject}, - body: ${email.body} - }` - } - ] - }; - chat:CreateChatCompletionResponse response = check openAiChat->/chat/completions.post(request); - if response.choices.length() < 1 { - return error("Unable to find any choices in the response."); - } - string content = check response.choices[0].message?.content.ensureType(string); - _ = check salesforce->create("EmailLead__c", check content.fromJsonStringWithType(Lead)); - - } -} - -function getMatchingEmails(gmail:LabelList labelList) returns Email[]|error { - string[] labelIdsToMatch = from gmail:Label {name, id} in labelList.labels - where ["Lead"].indexOf(name) != () - select id; - gmail:MsgSearchFilter searchFilter = { - includeSpamTrash: false, - labelIds: labelIdsToMatch - }; - gmail:MailThread[] matchingMailThreads = check from gmail:MailThread mailThread - in check gmail->listThreads(filter = searchFilter) - select mailThread; - foreach gmail:MailThread mailThread in matchingMailThreads { - _ = check gmail->modifyThread(mailThread.id, [], labelIdsToMatch); - } - gmail:Message[] matchingEmails = []; - foreach gmail:MailThread mailThread in matchingMailThreads { - gmail:MailThread response = check gmail->readThread(mailThread.id); - matchingEmails.push((response.messages)[0]); - } - Email[] emails = from gmail:Message message in matchingEmails - select check parseEmail(message); - return emails; -} - -function parseEmail(gmail:Message message) returns Email|error { - gmail:MessageBodyPart bodyPart = check message.emailBodyInText.ensureType(gmail:MessageBodyPart); - string bodyPartText = check bodyPart.data.ensureType(string); - string body = check mime:base64Decode(bodyPartText).ensureType(string); - return { - 'from: check message.headerFrom.ensureType(string), - subject: check message.headerSubject.ensureType(string), - body: body - }; -} diff --git a/examples/gmail-to-salesforce-lead/types.bal b/examples/gmail-to-salesforce-lead/types.bal deleted file mode 100644 index 2f576233..00000000 --- a/examples/gmail-to-salesforce-lead/types.bal +++ /dev/null @@ -1,18 +0,0 @@ -type Email record {| - string 'from; - string subject; - string body; -|}; - -type Name record {| - string firstName__c; - string lastName__c; -|}; - -type Lead record {| - *Name; - string email__c; - string phoneNumber__c; - string company__c; - string designation__c; -|}; diff --git a/examples/kafka_salesforce_integration/kafka-message-producer/Ballerina.toml b/examples/kafka_salesforce_integration/kafka-message-producer/Ballerina.toml deleted file mode 100644 index 3a008806..00000000 --- a/examples/kafka_salesforce_integration/kafka-message-producer/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "salesforce_examples" -name = "kafka_message_producer" -version = "0.1.0" -distribution = "2201.7.0" - -[build-options] -observabilityIncluded = true diff --git a/examples/kafka_salesforce_integration/kafka-message-producer/main.bal b/examples/kafka_salesforce_integration/kafka-message-producer/main.bal deleted file mode 100644 index 2a26e011..00000000 --- a/examples/kafka_salesforce_integration/kafka-message-producer/main.bal +++ /dev/null @@ -1,23 +0,0 @@ -import ballerina/http; -import ballerinax/kafka; - -public type ProductPrice readonly & record {| - string name; - float unitPrice; -|}; - -service / on new http:Listener(9090) { - private final kafka:Producer kafka; - - function init() returns error? { - self.kafka = check new (kafka:DEFAULT_URL); - } - - resource function post orders(@http:Payload anydata productPrice) returns http:Accepted|error { - check self.kafka->send({ - topic: "product-price-updates", - value: productPrice - }); - return http:ACCEPTED; - } -} diff --git a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Ballerina.toml b/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Ballerina.toml deleted file mode 100644 index c3caadd1..00000000 --- a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "salesforce_examples" -name = "kafka_salesforce_pricebook_update" -version = "0.1.0" -distribution = "2201.7.0" - -[build-options] -observabilityIncluded = true diff --git a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Docs/Flow diagram.png b/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Docs/Flow diagram.png deleted file mode 100644 index 0432cd3a..00000000 Binary files a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Docs/Flow diagram.png and /dev/null differ diff --git a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Readme.md b/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Readme.md deleted file mode 100644 index fbbe3f86..00000000 --- a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/Readme.md +++ /dev/null @@ -1,51 +0,0 @@ -# Kafka Message to Salesforce Price Book Update - -This example updates the product price in the [Salesforce](https://www.salesforce.com/) price book through [Kafka](https://kafka.apache.org/) and Salesforce integration. - -## Use case -Apache Kafka is a distributed event store and stream-processing platform, widely used for enterprise messaging applications. - -Organizations maintain details about products in various data stores such as ERP systems, databases, etc. Different business units can update these data stores. As these updates roll out, it's essential to implement reliable communication between business units and data stores to update data across all systems consistently. - -The following sample demonstrates a scenario in which a product's price in a price book in Salesforce is updated with product details fetched from a Kafka topic whenever a new message is received. - -## Prerequisites -* Salesforce account -* Install Kafka - -### Setting up a Salesforce account -1. Visit [Salesforce](https://www.salesforce.com/) and create a Salesforce Account. -2. Create a connected app and obtain the following credentials: - * Base URL (Endpoint) - * Access Token - * Client ID - * Client Secret - * Refresh Token - * Refresh Token URL -3. When you are setting up the connected app, select the following scopes under Selected OAuth Scopes: - * Access and manage your data (API) - * Perform requests on your behalf at any time (refresh_token, offline_access) - * Provide access to your data via the Web (web) -4. Provide the client ID and client secret to obtain the refresh token and access token. For more information on obtaining OAuth2 credentials, go to [Salesforce documentation](https://help.salesforce.com/articleView?id=remoteaccess_authenticate_overview.htm). -5. Once you obtained all configurations, add those to the `Config.toml` file. - -### Setting up Kafka. -1. To test in local machines, install the Kafka to your machine and start the server. You can follow the steps [here](https://kafka.apache.org/quickstart). - -## Configuration -Create a file called `Config.toml` at the root of the project. - -### Config.toml -``` -[.kafka_salesforce_pricebook_update] -salesforceBaseUrl = "" -salesforceAccessToken = "" -salesforcePriceBookId = "" -``` - -## Testing -1. First, run the kafka-message-producer to start the Kafka producer. -2. Start the Kafka subscriber by running the kafka-salesforce-pricebook_update. -3. Then send the required message to Kafka producer using `curl http://localhost:9090/orders -H "Content-type:application/json" -d "{\"name\": \"\", \"unitPrice\": }"`. - -When the new message is published to the Kafka topic, the subscriber will update the new price in the Salesforce price book. diff --git a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/main.bal b/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/main.bal deleted file mode 100644 index d3b33966..00000000 --- a/examples/kafka_salesforce_integration/kafka-salesforce-pricebook_update/main.bal +++ /dev/null @@ -1,45 +0,0 @@ -import ballerinax/kafka; -import ballerinax/salesforce; - -configurable string salesforceAccessToken = ?; -configurable string salesforceBaseUrl = ?; -configurable string salesforcePriceBookId = ?; - -public type ProductPrice readonly & record {| - string name; - float unitPrice; -|}; - -public type ProductPriceUpdate readonly & record {| - float UnitPrice; -|}; - -listener kafka:Listener priceListener = new (kafka:DEFAULT_URL, { - groupId: "order-group-id", - topics: "product-price-updates" -}); - -final salesforce:Client salesforce = check new ({ - baseUrl: salesforceBaseUrl, - auth: { - token: salesforceAccessToken - } -}); - -service on priceListener { - isolated remote function onConsumerRecord(ProductPrice[] prices) returns error? { - foreach ProductPrice {name, unitPrice} in prices { - stream retrievedStream = check salesforce->query( - string `SELECT Id FROM PricebookEntry - WHERE Pricebook2Id = '${salesforcePriceBookId}' AND - Name = '${name}'`); - record {}[] retrieved = check from record {} entry in retrievedStream - select entry; - anydata pricebookEntryId = retrieved[0]["Id"]; - if pricebookEntryId is string { - ProductPriceUpdate updatedPrice = {UnitPrice: unitPrice}; - check salesforce->update("PricebookEntry", pricebookEntryId, updatedPrice); - } - } - } -} diff --git a/examples/rest_api_usecases/create_sobjects/Ballerina.toml b/examples/rest_api_usecases/create_sobjects/Ballerina.toml new file mode 100644 index 00000000..4c87ec52 --- /dev/null +++ b/examples/rest_api_usecases/create_sobjects/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_rest_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/create_sobjects/README.md b/examples/rest_api_usecases/create_sobjects/README.md new file mode 100644 index 00000000..5a892f58 --- /dev/null +++ b/examples/rest_api_usecases/create_sobjects/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to create sObjects. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/sobject_create.bal b/examples/rest_api_usecases/create_sobjects/sobject_create.bal similarity index 100% rename from samples/rest_api_usecases/sobject_create.bal rename to examples/rest_api_usecases/create_sobjects/sobject_create.bal diff --git a/examples/rest_api_usecases/delete_sobject/Ballerina.toml b/examples/rest_api_usecases/delete_sobject/Ballerina.toml new file mode 100644 index 00000000..2cc6d065 --- /dev/null +++ b/examples/rest_api_usecases/delete_sobject/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_getbyid_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/delete_sobject/README.md b/examples/rest_api_usecases/delete_sobject/README.md new file mode 100644 index 00000000..790fef9a --- /dev/null +++ b/examples/rest_api_usecases/delete_sobject/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to delete sObjects. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/sobject_delete.bal b/examples/rest_api_usecases/delete_sobject/sobject_delete.bal similarity index 100% rename from samples/rest_api_usecases/sobject_delete.bal rename to examples/rest_api_usecases/delete_sobject/sobject_delete.bal diff --git a/examples/rest_api_usecases/get_by_id/Ballerina.toml b/examples/rest_api_usecases/get_by_id/Ballerina.toml new file mode 100644 index 00000000..2cc6d065 --- /dev/null +++ b/examples/rest_api_usecases/get_by_id/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_getbyid_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/get_by_id/README.md b/examples/rest_api_usecases/get_by_id/README.md new file mode 100644 index 00000000..bd2d99de --- /dev/null +++ b/examples/rest_api_usecases/get_by_id/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to get sObject by Id. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/sobject_get_by_id.bal b/examples/rest_api_usecases/get_by_id/sobject_get_by_id.bal similarity index 100% rename from samples/rest_api_usecases/sobject_get_by_id.bal rename to examples/rest_api_usecases/get_by_id/sobject_get_by_id.bal diff --git a/examples/rest_api_usecases/update_sobject/Ballerina.toml b/examples/rest_api_usecases/update_sobject/Ballerina.toml new file mode 100644 index 00000000..7abe8777 --- /dev/null +++ b/examples/rest_api_usecases/update_sobject/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_update_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/update_sobject/README.md b/examples/rest_api_usecases/update_sobject/README.md new file mode 100644 index 00000000..637a5e7b --- /dev/null +++ b/examples/rest_api_usecases/update_sobject/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to update sObjects. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/sobject_update.bal b/examples/rest_api_usecases/update_sobject/sobject_update.bal similarity index 100% rename from samples/rest_api_usecases/sobject_update.bal rename to examples/rest_api_usecases/update_sobject/sobject_update.bal diff --git a/examples/rest_api_usecases/use_query_api/Ballerina.toml b/examples/rest_api_usecases/use_query_api/Ballerina.toml new file mode 100644 index 00000000..6d323665 --- /dev/null +++ b/examples/rest_api_usecases/use_query_api/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_query_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/use_query_api/README.md b/examples/rest_api_usecases/use_query_api/README.md new file mode 100644 index 00000000..ba32d8a1 --- /dev/null +++ b/examples/rest_api_usecases/use_query_api/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to query sObjects. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/find_record_by_query_stream.bal b/examples/rest_api_usecases/use_query_api/find_record_by_query_stream.bal similarity index 100% rename from samples/rest_api_usecases/find_record_by_query_stream.bal rename to examples/rest_api_usecases/use_query_api/find_record_by_query_stream.bal diff --git a/examples/rest_api_usecases/use_search_api/Ballerina.toml b/examples/rest_api_usecases/use_search_api/Ballerina.toml new file mode 100644 index 00000000..d8500275 --- /dev/null +++ b/examples/rest_api_usecases/use_search_api/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_search_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/rest_api_usecases/use_search_api/README.md b/examples/rest_api_usecases/use_search_api/README.md new file mode 100644 index 00000000..82d34703 --- /dev/null +++ b/examples/rest_api_usecases/use_search_api/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke REST API of Salesforce to search sObjects. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/rest_api_usecases/search_record_by_string_stream.bal b/examples/rest_api_usecases/use_search_api/search_record_by_string_stream.bal similarity index 100% rename from samples/rest_api_usecases/search_record_by_string_stream.bal rename to examples/rest_api_usecases/use_search_api/search_record_by_string_stream.bal diff --git a/examples/salesforce-new-contact-to-twilio-sms/Ballerina.toml b/examples/salesforce-new-contact-to-twilio-sms/Ballerina.toml deleted file mode 100644 index 5d1c4194..00000000 --- a/examples/salesforce-new-contact-to-twilio-sms/Ballerina.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -org = "salesforce_examples" -name = "sfdc_new_contact_to_twilio_sms" -distribution = "2201.7.0" -version = "0.1.0" -[build-options] -observabilityIncluded = true diff --git a/examples/salesforce-new-contact-to-twilio-sms/Readme.md b/examples/salesforce-new-contact-to-twilio-sms/Readme.md deleted file mode 100644 index 7c58a962..00000000 --- a/examples/salesforce-new-contact-to-twilio-sms/Readme.md +++ /dev/null @@ -1,52 +0,0 @@ -# Salesforce New Contact to Twilio SMS - -This example sends a [Twilio](https://www.twilio.com/) SMS for every new [Salesforce](https://www.salesforce.com/) contact. - -## Use case -Twilio is a cloud communications platform as a service (CPaaS) company. It allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs. - -As most organizations maintain a well-organized sales process, it is important to follow up with Contacts as soon as they are added to Salesforce. There may be a specific person who wanted to be on alert of new Salesforce contacts. Any time you create a new Contact in Salesforce, an SMS message will be automatically sent to the specific person via Twilio. - -The following sample demonstrates a scenario in which a Twilio SMS message containing all the defined fields in Contacts SObject is sent to a given mobile number when a new Contact is created in Salesforce. - -## Prerequisites -* Twilio account -* Salesforce account - -### Setting up a Salesforce account -1. Create a Salesforce account and create a connected app by visiting [Salesforce](https://www.salesforce.com). -2. Salesforce username and password will be needed for initializing the listener. -3. Once you have obtained all configurations, Replace relevant places in the `Config.toml` file with your data. -4. [Select Objects](https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_select_objects.htm) for Change Notifications in the User Interface of Salesforce account. - -### Setting up a Twilio account -1. Create a [Twilio developer account](https://www.twilio.com/). -2. Obtain the Account SID and Auth Token from the project dashboard. -3. Obtain the phone number from the project dashboard and set it as the value of the `fromNumber` variable in the `Config.toml`. -4. Give a mobile number where the SMS should be sent as the value of the `toNumber` variable in the `Config.toml`. -5. Once you have obtained all configurations, add those to the `Config.toml` file. - -## Configuration -Create a file called `Config.toml` at the root of the project. - -## Config.toml -``` -[.sfdc_new_contact_to_twilio_sms] -fromNumber = "" -toNumber = "" - -[.sfdc_new_contact_to_twilio_sms.salesforceListenerConfig] -username = "" -password = "" - -[.sfdc_new_contact_to_twilio_sms.twilioClientConfig] -accountSId = "" -authToken = "" - -``` -Phone numbers must be provided in E.164 format: +, for example: +16175551212 - -## Testing -Run the Ballerina project created by the integration template by executing `bal run` from the root. - -You can check the Twilio SMS for information related to the new Salesforce Contact. diff --git a/examples/salesforce-new-contact-to-twilio-sms/docs/images/template_flow.png b/examples/salesforce-new-contact-to-twilio-sms/docs/images/template_flow.png deleted file mode 100644 index c8b658c2..00000000 Binary files a/examples/salesforce-new-contact-to-twilio-sms/docs/images/template_flow.png and /dev/null differ diff --git a/examples/salesforce-new-contact-to-twilio-sms/main.bal b/examples/salesforce-new-contact-to-twilio-sms/main.bal deleted file mode 100644 index 353aa569..00000000 --- a/examples/salesforce-new-contact-to-twilio-sms/main.bal +++ /dev/null @@ -1,58 +0,0 @@ -import ballerinax/trigger.salesforce; -import ballerinax/twilio; - -type SalesforceListenerConfig record {| - string username; - string password; -|}; - -type TwilioClientConfig record {| - string accountSId; - string authToken; -|}; - -// Salesforce configuration parameters -configurable SalesforceListenerConfig salesforceListenerConfig = ?; - -// Twilio configuration parameters -configurable TwilioClientConfig twilioClientConfig = ?; -configurable string fromNumber = ?; -configurable string toNumber = ?; - -listener salesforce:Listener sfdcEventListener = new ({ - username: salesforceListenerConfig.username, - password: salesforceListenerConfig.password, - channelName: "/data/ContactChangeEvent" -}); - -final twilio:Client twilio = check new ({ - twilioAuth: { - accountSId: twilioClientConfig.accountSId, - authToken: twilioClientConfig.authToken - } -}); - -service salesforce:RecordService on sfdcEventListener { - isolated remote function onCreate(salesforce:EventData payload) returns error? { - string[] nameParts = re `,`.split(payload.changedData["Name"].toString()); - string firstName = (nameParts.length() >= 2) ? re `=`.split(nameParts[0])[1] : ""; - string lastName = (nameParts.length() >= 2) ? - re `=`.split(re `\}`.replace(nameParts[1], ""))[1] : - re `=`.split(re `\}`.replace(nameParts[0], ""))[1]; - _ = check twilio->sendSms(fromNumber, toNumber, - string `New contact is created! | Name: ${firstName} ${lastName} | Created Date: - ${(check payload.changedData.CreatedDate).toString()}`); - } - - isolated remote function onUpdate(salesforce:EventData payload) returns error? { - return; - } - - isolated remote function onDelete(salesforce:EventData payload) returns error? { - return; - } - - isolated remote function onRestore(salesforce:EventData payload) returns error? { - return; - } -} diff --git a/examples/soap_api_usecases/convert_lead/Ballerina.toml b/examples/soap_api_usecases/convert_lead/Ballerina.toml new file mode 100644 index 00000000..e26a57b2 --- /dev/null +++ b/examples/soap_api_usecases/convert_lead/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "salesforce_examples" +name = "use_soap_api" +version = "0.1.0" +distribution = "2201.8.2" diff --git a/examples/soap_api_usecases/convert_lead/README.md b/examples/soap_api_usecases/convert_lead/README.md new file mode 100644 index 00000000..eb2afc6c --- /dev/null +++ b/examples/soap_api_usecases/convert_lead/README.md @@ -0,0 +1,28 @@ +# Use REST API + +This example demonstrates how to invoke SOAP API of Salesforce to convert Leads. + +## Prerequisites + +### 1. Set up +Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials. + +### 2. Configuration + +Configure Salesforce API credentials in Config.toml in the example directory: + +```toml +clientId = "" +clientSecret = "" +refreshToken = "" +refreshUrl = "" +baseUrl = "" +``` + +## Run the example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/samples/soap_api_usecases/convert_lead.bal b/examples/soap_api_usecases/convert_lead/convert_lead.bal similarity index 80% rename from samples/soap_api_usecases/convert_lead.bal rename to examples/soap_api_usecases/convert_lead/convert_lead.bal index 0b340030..76e3f418 100644 --- a/samples/soap_api_usecases/convert_lead.bal +++ b/examples/soap_api_usecases/convert_lead/convert_lead.bal @@ -16,14 +16,13 @@ import ballerinax/salesforce.soap; import ballerina/log; -import ballerina/os; -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); +// Create Salesforce client configuration by reading from environment. +configurable string clientId = ?; +configurable string clientSecret = ?; +configurable string refreshToken = ?; +configurable string refreshUrl = ?; +configurable string baseUrl = ?; public function main() returns error? { soap:Client salesforceClient = check new ({ diff --git a/samples/bulk_api_usecases/bulk-operations-csv/bulk_file_insert_csv.bal b/samples/bulk_api_usecases/bulk-operations-csv/bulk_file_insert_csv.bal deleted file mode 100644 index 286145b6..00000000 --- a/samples/bulk_api_usecases/bulk-operations-csv/bulk_file_insert_csv.bal +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/io; -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - string csvContactsFilePath = "resources/contacts.csv"; - - bulk:BulkJob|error insertJob = bulkClient->createJob("insert", "Contact", "CSV"); - - if insertJob is bulk:BulkJob { - io:ReadableByteChannel|io:Error rbc = io:openReadableFile(csvContactsFilePath); - if rbc is io:ReadableByteChannel { - error|bulk:BatchInfo batch = bulkClient->addBatch(insertJob, rbc); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Added Successfully" : "Failed to add the Batch"; - batchId = batch.id; - log:printInfo(message + " : " + message + " " + batchId); - } else { - log:printError(batch.message()); - } - } - - else { - log:printError(rbc.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(insertJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(insertJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(insertJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(insertJob, batchId); - if batchRequest is string { - string message = (re `\n`.split(batchRequest)).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(insertJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(insertJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_delete_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_delete_json.bal deleted file mode 100644 index 2830b18a..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_delete_json.bal +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Avenra", "Stanis", "Software Engineer Level 1"); - string id2 = check getContactIdByName("Irma", "Martin", "Software Engineer Level 1"); - - json contactsToDelete = [ - {"Id": id1}, - {"Id": id2} - ]; - - bulk:BulkJob|error deleteJob = bulkClient->createJob("delete", "Contact", "JSON"); - - if deleteJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(deleteJob, contactsToDelete); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Contacts Successfully uploaded to delete" : "Failed to upload the Contacts to delete"; - log:printInfo(message); - batchId = batch.id; - - } else { - log:printError(batch.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(deleteJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(deleteJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(deleteJob, batchId); - if batchRequest is json { - json[]|error batchRequestArr = batchRequest; - if batchRequestArr is json[] { - string message = batchRequestArr.length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - } else { - log:printError(batchRequestArr.message()); - } - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(deleteJob, batchId); - if batchResult is bulk:Result[] { - string message = batchResult.length() > 0 ? "Batch Result Received Successfully" : "Failed to Retrieve Batch Result"; - log:printInfo(message); - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(deleteJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; - diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_file_insert_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_file_insert_json.bal deleted file mode 100644 index 6dd2ce47..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_file_insert_json.bal +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/io; -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - string batchId = ""; - string jsonContactsFilePath = "resources/contacts.json"; - - bulk:BulkJob|error insertJob = bulkClient->createJob("insert", "Contact", "JSON"); - - if insertJob is bulk:BulkJob { - io:ReadableByteChannel|io:Error rbc = io:openReadableFile(jsonContactsFilePath); - if rbc is io:ReadableByteChannel { - error|bulk:BatchInfo batch = bulkClient->addBatch(insertJob, rbc); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Added Successfully" : "Failed to add the Batch"; - batchId = batch.id; - log:printInfo(message + " : " + message + " " + batchId); - } else { - log:printError(batch.message()); - } - } - else { - log:printError(rbc.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(insertJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(insertJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(insertJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(insertJob, batchId); - if batchRequest is json { - json[]|error batchRequestArr = batchRequest; - if batchRequestArr is json[] { - string message = batchRequestArr.length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - } else { - log:printError(batchRequestArr.message()); - } - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(insertJob, batchId); - if batchResult is bulk:Result[] { - string message = batchResult.length() > 0 ? "Batch Result Received Successfully" : "Failed to Retrieve Batch Result"; - log:printInfo(message); - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(insertJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_insert_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_insert_json.bal deleted file mode 100644 index d4e9d5ac..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_insert_json.bal +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - json contacts = [ - { - description: "Created_from_Ballerina_Sf_Bulk_API", - FirstName: "Avenra", - LastName: "Stanis", - Title: "Software Engineer Level 1", - Phone: "0475626670", - Email: "remusArf@gmail.com", - My_External_Id__c: "860" - }, - { - description: "Created_from_Ballerina_Sf_Bulk_API", - FirstName: "Irma", - LastName: "Martin", - Title: "Software Engineer Level 1", - Phone: "0465616170", - Email: "irmaHel@gmail.com", - My_External_Id__c: "861" - } - ]; - - bulk:BulkJob|error insertJob = bulkClient->createJob("insert", "Contact", "JSON"); - - if insertJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(insertJob, contacts); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Added Successfully" : "Failed to add the Batch"; - batchId = batch.id; - log:printInfo(message + " : " + message + " " + batchId); - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(insertJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(insertJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(insertJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(insertJob, batchId); - if batchRequest is json { - json[]|error batchRequestArr = batchRequest; - if batchRequestArr is json[] { - string message = batchRequestArr.length() == 2 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - } else { - log:printError(batchRequestArr.message()); - } - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(insertJob, batchId); - if batchResult is bulk:Result[] { - string message = batchResult.length() > 0 ? "Batch Result Received Successfully" : "Failed to Retrieve Batch Result"; - log:printInfo(message); - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(insertJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - else { - log:printInfo(insertJob.message()); - } - -} diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_query_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_query_json.bal deleted file mode 100644 index 9f856561..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_query_json.bal +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - string queryStr = "SELECT Id, Name FROM Contact WHERE Title='Software Engineer Level 1'"; - - bulk:BulkJob|error queryJob = bulkClient->createJob("query", "Contact", "JSON"); - - if queryJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(queryJob, queryStr); - if batch is bulk:BatchInfo { - _ = batch.id.length() > 0 ? "Query Executed Successfully" : "Failed to Execute the Quesry"; - batchId = batch.id; - } else { - log:printError(batch.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(queryJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(queryJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(queryJob, batchId); - if batchRequest is string { - string message = batchRequest.startsWith("SELECT") ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(queryJob, batchId); - - if batchResult is json { - json[]|error batchResultArr = batchResult; - if batchResultArr is json[] { - //io:println("count : " + batchResultArr.length().toString()); - log:printInfo("Number of Records Received :" + batchResultArr.length().toString()); - } else { - string msg = batchResultArr.toString(); - log:printError(msg); - } - } else if batchResult is error { - string msg = batchResult.message(); - log:printError(msg); - } else { - log:printError("Invalid Batch Result!"); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(queryJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_update_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_update_json.bal deleted file mode 100644 index f3fd460b..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_update_json.bal +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Avenra", "Stanis", "Software Engineer Level 1"); - string id2 = check getContactIdByName("Irma", "Martin", "Software Engineer Level 1"); - - json contacts = [ - { - description: "Created_from_Ballerina_Sf_Bulk_API", - Id: id1, - FirstName: "Avenra", - LastName: "Stanis", - Title: "Software Engineer Level 1", - Phone: "0937443355", - Email: "remusArf@gmail.com", - My_External_Id__c: "860" - }, - { - description: "Created_from_Ballerina_Sf_Bulk_API", - Id: id2, - FirstName: "Irma", - LastName: "Martin", - Title: "Software Engineer Level 1", - Phone: "0893345755", - Email: "irmaHel@gmail.com", - My_External_Id__c: "861" - } - ]; - - bulk:BulkJob|error updateJob = bulkClient->createJob("update", "Contact", "JSON"); - - if updateJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(updateJob, contacts); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Updated Successfully" : "Failed to Update the Batch"; - batchId = batch.id; - log:printInfo(message); - } else { - log:printError(batch.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(updateJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(updateJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(updateJob, batchId); - if batchRequest is json { - json[]|error batchRequestArr = batchRequest; - if batchRequestArr is json[] { - string message = batchRequestArr.length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - } else { - log:printError(batchRequestArr.message()); - } - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(updateJob, batchId); - if batchResult is bulk:Result[] { - string message = batchResult.length() > 0 ? "Batch Result Received Successfully" : "Failed to Retrieve Batch Result"; - log:printInfo(message); - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(updateJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; - diff --git a/samples/bulk_api_usecases/bulk-operations-json/bulk_upsert_json.bal b/samples/bulk_api_usecases/bulk-operations-json/bulk_upsert_json.bal deleted file mode 100644 index 367bd0ef..00000000 --- a/samples/bulk_api_usecases/bulk-operations-json/bulk_upsert_json.bal +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Avenra", "Stanis", "Software Engineer Level 1"); - string id2 = check getContactIdByName("Irma", "Martin", "Software Engineer Level 1"); - - json contacts = [ - { - description: "Created_from_Ballerina_Sf_Bulk_API", - Id: id1, - FirstName: "Avenra", - LastName: "Stanis", - Title: "Software Engineer Level 1", - Phone: "0937443354", - Email: "remusArf@gmail.com", - My_External_Id__c: "860", - Department: "R&D" - }, - { - description: "Created_from_Ballerina_Sf_Bulk_API", - Id: id2, - FirstName: "Irma", - LastName: "Martin", - Title: "Software Engineer Level 1", - Phone: "0893345789", - Email: "irmaHel@gmail.com", - My_External_Id__c: "861", - Department: "R&D" - } - ]; - - bulk:BulkJob|error updateJob = bulkClient->createJob("upsert", "Contact", "JSON", "My_External_Id__c"); - - if updateJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(updateJob, contacts); - if batch is bulk:BatchInfo { - batchId = batch.id; - string message = batch.id.length() > 0 ? "Batch added to upsert Successfully" : "Failed to add the batch"; - log:printInfo(message); - } else { - log:printError(batch.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(updateJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(updateJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(updateJob, batchId); - if batchRequest is json { - json[]|error batchRequestArr = batchRequest; - if batchRequestArr is json[] { - string message = batchRequestArr.length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - } else { - log:printError(batchRequestArr.message()); - } - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(updateJob, batchId); - if batchResult is bulk:Result[] { - string message = batchResult.length() > 0 ? "Batch Result Received Successfully" : "Failed to Retrieve Batch Result"; - log:printInfo(message); - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(updateJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; - diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_delete_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_delete_xml.bal deleted file mode 100644 index e7e04036..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_delete_xml.bal +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Wanda", "Davidson", "Software Engineer Level 3"); - string id2 = check getContactIdByName("Natasha", "Romenoff", "Software Engineer Level 3"); - - xml contactsToDelete = xml ` - - ${id1} - - - ${id2} - - `; - - bulk:BulkJob|error deleteJob = bulkClient->createJob("delete", "Contact", "XML"); - - if deleteJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(deleteJob, contactsToDelete); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Contacts Successfully uploaded to delete" : "Failed to upload the Contacts to delete"; - log:printInfo(message); - batchId = batch.id; - - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(deleteJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(deleteJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(deleteJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(deleteJob, batchId); - if batchRequest is xml { - string message = (batchRequest/<*>).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(deleteJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(deleteJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_file_insert_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_file_insert_xml.bal deleted file mode 100644 index b693eca8..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_file_insert_xml.bal +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/io; -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - string xmlContactsFilePath = "resources/contacts.xml"; - - bulk:BulkJob|error insertJob = bulkClient->createJob("insert", "Contact", "XML"); - - if insertJob is bulk:BulkJob { - io:ReadableByteChannel|io:Error rbc = io:openReadableFile(xmlContactsFilePath); - if rbc is io:ReadableByteChannel { - error|bulk:BatchInfo batch = bulkClient->addBatch(insertJob, rbc); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Added Successfully" : "Failed to add the Batch"; - batchId = batch.id; - log:printInfo(message + " : " + message + " " + batchId); - } else { - log:printError(batch.message()); - } - } - else { - log:printError(rbc.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(insertJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(insertJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(insertJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(insertJob, batchId); - if batchRequest is xml { - string message = (batchRequest/<*>).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(insertJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(insertJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_insert_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_insert_xml.bal deleted file mode 100644 index f9b3d693..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_insert_xml.bal +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - xml contacts = xml ` - - Created_from_Ballerina_Sf_Bulk_API - Wanda - Davidson - Software Engineer Level 03 - 099116123 - wanda67@yahoo.com - 864 - - - Created_from_Ballerina_Sf_Bulk_API - Natasha - Romenoff - Software Engineer Level 03 - 086755643 - natashaRom@gmail.com - 865 - - `; - - bulk:BulkJob|error insertJob = bulkClient->createJob("insert", "Contact", "XML"); - - if insertJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(insertJob, contacts); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Added Successfully" : "Failed to add the Batch"; - batchId = batch.id; - log:printInfo(message + " : " + message + " " + batchId); - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(insertJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(insertJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(insertJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(insertJob, batchId); - if batchRequest is xml { - string message = (batchRequest/<*>).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(insertJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(insertJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_query_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_query_xml.bal deleted file mode 100644 index 66cb5637..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_query_xml.bal +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - - string batchId = ""; - - // Create Salesforce client. - bulk:Client bulkClient = check new (sfConfig); - - string queryStr = "SELECT Id, Name FROM Contact WHERE Title='Software Engineer Level 3'"; - - bulk:BulkJob|error queryJob = bulkClient->createJob("query", "Contact", "XML"); - - if queryJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(queryJob, queryStr); - if batch is bulk:BatchInfo { - _ = batch.id.length() > 0 ? "Query Executed Successfully" : "Failed to Execute the Quesry"; - batchId = batch.id; - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(queryJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(queryJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(queryJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(queryJob, batchId); - if batchRequest is string { - string message = batchRequest.startsWith("SELECT") ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(queryJob, batchId); - if batchResult is xml { - log:printInfo("Number of Records Received :" + ((batchResult/<*>).length().toString())); - } else if batchResult is error { - string msg = batchResult.message(); - log:printError(msg); - } else { - log:printError("Invalid Batch Result!"); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(queryJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } -} diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_update_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_update_xml.bal deleted file mode 100644 index 4c1c4e4f..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_update_xml.bal +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Wanda", "Davidson", "Software Engineer Level 03"); - string id2 = check getContactIdByName("Natasha", "Romenoff", "Software Engineer Level 03"); - - xml contacts = xml ` - - Created_from_Ballerina_Sf_Bulk_API - ${id1} - Wanda - Davidson - Software Engineer Level 3 - 0991161233 - wanda67@yahoo.com - 864 - - - Created_from_Ballerina_Sf_Bulk_API - ${id2} - Natasha - Romenoff - Software Engineer Level 3 - 0867556833 - natashaRom@gmail.com - 865 - - `; - - bulk:BulkJob|error updateJob = bulkClient->createJob("update", "Contact", "XML"); - - if updateJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(updateJob, contacts); - if batch is bulk:BatchInfo { - string message = batch.id.length() > 0 ? "Batch Updated Successfully" : "Failed to Update the Batch"; - batchId = batch.id; - log:printInfo(message); - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(updateJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(updateJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(updateJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(updateJob, batchId); - if batchRequest is xml { - string message = (batchRequest/<*>).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(updateJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(updateJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; diff --git a/samples/bulk_api_usecases/bulk-operations-xml/bulk_upsert_xml.bal b/samples/bulk_api_usecases/bulk-operations-xml/bulk_upsert_xml.bal deleted file mode 100644 index db921d5e..00000000 --- a/samples/bulk_api_usecases/bulk-operations-xml/bulk_upsert_xml.bal +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce.bulk; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -bulk:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -// Create Salesforce client. -salesforce:Client baseClient = check new (sfConfig); -bulk:Client bulkClient = check new (sfConfig); - -public function main() returns error? { - - string batchId = ""; - - string id1 = check getContactIdByName("Wanda", "Davidson", "Software Engineer Level 3"); - string id2 = check getContactIdByName("Natasha", "Romenoff", "Software Engineer Level 3"); - - xml contacts = xml ` - - Created_from_Ballerina_Sf_Bulk_API - ${id1} - Wanda - Davidson - Software Engineer Level 3 - 0991161283 - wanda67@yahoo.com - 864 - Finance - - - Created_from_Ballerina_Sf_Bulk_API - ${id2} - Natasha - Romenoff - Software Engineer Level 3 - 0867556843 - natashaRom@gmail.com - 865 - Finance - - `; - - bulk:BulkJob|error updateJob = bulkClient->createJob("upsert", "Contact", "XML", "My_External_Id__c"); - - if updateJob is bulk:BulkJob { - error|bulk:BatchInfo batch = bulkClient->addBatch(updateJob, contacts); - if batch is bulk:BatchInfo { - batchId = batch.id; - string message = batch.id.length() > 0 ? "Batch added to upsert Successfully" : "Failed to add the batch"; - log:printInfo(message); - } else { - log:printError(batch.message()); - } - - //get job info - error|bulk:JobInfo jobInfo = bulkClient->getJobInfo(updateJob); - if jobInfo is bulk:JobInfo { - string message = jobInfo.id.length() > 0 ? "Jon Info Received Successfully" : "Failed Retrieve Job Info"; - log:printInfo(message); - } else { - log:printError(jobInfo.message()); - } - - //get batch info - error|bulk:BatchInfo batchInfo = bulkClient->getBatchInfo(updateJob, batchId); - if batchInfo is bulk:BatchInfo { - string message = batchInfo.id == batchId ? "Batch Info Received Successfully" : "Failed to Retrieve Batch Info"; - log:printInfo(message); - } else { - log:printError(batchInfo.message()); - } - - //get all batches - error|bulk:BatchInfo[] batchInfoList = bulkClient->getAllBatches(updateJob); - if batchInfoList is bulk:BatchInfo[] { - string message = batchInfoList.length() == 1 ? "All Batches Received Successfully" : "Failed to Retrieve All Batches"; - log:printInfo(message); - } else { - log:printError(batchInfoList.message()); - } - - //get batch request - var batchRequest = bulkClient->getBatchRequest(updateJob, batchId); - if batchRequest is xml { - string message = (batchRequest/<*>).length() > 0 ? "Batch Request Received Successfully" : "Failed to Retrieve Batch Request"; - log:printInfo(message); - - } else if batchRequest is error { - log:printError(batchRequest.message()); - } else { - log:printError(batchRequest.toString()); - } - - //get batch result - var batchResult = bulkClient->getBatchResult(updateJob, batchId); - if batchResult is bulk:Result[] { - foreach bulk:Result res in batchResult { - if !res.success { - log:printError("Failed result, res=" + res.toString(), err = ()); - } - } - } else if batchResult is error { - log:printError(batchResult.message()); - } else { - log:printError(batchResult.toString()); - } - - //close job - error|bulk:JobInfo closedJob = bulkClient->closeJob(updateJob); - if closedJob is bulk:JobInfo { - string message = closedJob.state == "Closed" ? "Job Closed Successfully" : "Failed to Close the Job"; - log:printInfo(message); - } else { - log:printError(closedJob.message()); - } - } - -} - -function getContactIdByName(string firstName, string lastName, string title) returns string|error { - string contactId = ""; - string sampleQuery = string `SELECT Id FROM Contact WHERE FirstName='${firstName}' AND LastName='${lastName}' - AND Title='${title}' LIMIT 1`; - stream queryResults = check baseClient->query(sampleQuery); - ResultValue|error? result = queryResults.next(); - if result is ResultValue { - contactId = check result.value.get("Id").ensureType(); - } else { - log:printError(msg = "Getting Contact ID by name failed."); - } - return contactId; -} - -type ResultValue record {| - record {} value; -|}; diff --git a/samples/rest_api_usecases/org-metadata-usecases/get_api_version.bal b/samples/rest_api_usecases/org-metadata-usecases/get_api_version.bal deleted file mode 100644 index 694aabb5..00000000 --- a/samples/rest_api_usecases/org-metadata-usecases/get_api_version.bal +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - salesforce:Version[]|error apiVersions = baseClient->getApiVersions(); - - if apiVersions is salesforce:Version[] { - log:printInfo("Versions retrieved successfully : " + apiVersions.toString()); - } else { - log:printError(msg = apiVersions.message()); - } - -} diff --git a/samples/rest_api_usecases/org-metadata-usecases/get_org_limits.bal b/samples/rest_api_usecases/org-metadata-usecases/get_org_limits.bal deleted file mode 100644 index 4e616d67..00000000 --- a/samples/rest_api_usecases/org-metadata-usecases/get_org_limits.bal +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - map|error orgLimits = baseClient->getLimits(); - - if orgLimits is map { - log:printInfo("Versions retrieved successfully : " + orgLimits.toString()); - } else { - log:printError(msg = orgLimits.message()); - } - -} diff --git a/samples/rest_api_usecases/org-metadata-usecases/get_organizational_data.bal b/samples/rest_api_usecases/org-metadata-usecases/get_organizational_data.bal deleted file mode 100644 index 5697b274..00000000 --- a/samples/rest_api_usecases/org-metadata-usecases/get_organizational_data.bal +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - salesforce:Version[]|error apiVersions = baseClient->getApiVersions(); - - if apiVersions is salesforce:Version[] { - log:printInfo("Versions retrieved successfully : " + apiVersions.toString()); - } else { - log:printError(msg = apiVersions.message()); - } - - map|error apiVersionResources = baseClient->getResources("v48.0"); - - if apiVersionResources is map { - log:printInfo("Versions retrieved successfully : " + apiVersionResources.toString()); - } else { - log:printError(msg = apiVersionResources.message()); - } - - map|error apiLimits = baseClient->getLimits(); - - if apiLimits is map { - log:printInfo("Versions retrieved successfully : " + apiLimits.toString()); - } else { - log:printError(msg = apiLimits.message()); - } - -} diff --git a/samples/rest_api_usecases/org-metadata-usecases/get_version_resources.bal b/samples/rest_api_usecases/org-metadata-usecases/get_version_resources.bal deleted file mode 100644 index 69e024d7..00000000 --- a/samples/rest_api_usecases/org-metadata-usecases/get_version_resources.bal +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - map|error apiVersionResources = baseClient->getResources("v48.0"); - - if apiVersionResources is map { - log:printInfo("Versions retrieved successfully : " + apiVersionResources.toString()); - } else { - log:printError(msg = apiVersionResources.message()); - } -} diff --git a/samples/rest_api_usecases/sobject-metadata-usecases/describe_available_objects.bal b/samples/rest_api_usecases/sobject-metadata-usecases/describe_available_objects.bal deleted file mode 100644 index c0306547..00000000 --- a/samples/rest_api_usecases/sobject-metadata-usecases/describe_available_objects.bal +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - salesforce:OrganizationMetadata|error availableObjsDes = baseClient->getOrganizationMetaData(); - - if availableObjsDes is salesforce:OrganizationMetadata { - int|error countSobjects = availableObjsDes.sobjects.length(); - if countSobjects is int { - log:printInfo("Number of SObjects Received = " + countSobjects.toString()); - } - else { - log:printError("No SObjects Found"); - } - } else { - log:printError(msg = availableObjsDes.message()); - } - -} diff --git a/samples/rest_api_usecases/sobject-metadata-usecases/describe_sobject.bal b/samples/rest_api_usecases/sobject-metadata-usecases/describe_sobject.bal deleted file mode 100644 index fe08097c..00000000 --- a/samples/rest_api_usecases/sobject-metadata-usecases/describe_sobject.bal +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - string objName = "Account"; - - salesforce:SObjectMetaData|error objDesc = baseClient->describe(objName); - - if objDesc is salesforce:SObjectMetaData { - log:printInfo("Object description received : " + objDesc.toString()); - } else { - log:printError(msg = objDesc.message()); - } -} diff --git a/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_info.bal b/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_info.bal deleted file mode 100644 index 7c1842c8..00000000 --- a/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_info.bal +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - string objName = "Account"; - salesforce:SObjectBasicInfo|error sobjectInfo = baseClient->getBasicInfo(objName); - - if sobjectInfo is salesforce:SObjectBasicInfo { - log:printInfo("SObject basic info received " + sobjectInfo.toString()); - } else { - log:printError(msg = sobjectInfo.message()); - } - -} diff --git a/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_platformAction.bal b/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_platformAction.bal deleted file mode 100644 index 62b0ed5e..00000000 --- a/samples/rest_api_usecases/sobject-metadata-usecases/get_sobject_platformAction.bal +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - salesforce:SObjectBasicInfo|error actionInfo = baseClient->getPlatformAction(); - - if actionInfo is salesforce:SObjectBasicInfo { - log:printInfo("Platform Action Info Received : " + actionInfo.toString()); - } else { - log:printError(msg = actionInfo.message()); - } -} diff --git a/samples/rest_api_usecases/sojbect_get_record_by_ext.bal b/samples/rest_api_usecases/sojbect_get_record_by_ext.bal deleted file mode 100644 index 4f3d2496..00000000 --- a/samples/rest_api_usecases/sojbect_get_record_by_ext.bal +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/salesforce; -import ballerina/os; - -// Create Salesforce client configuration by reading from environemnt. -configurable string clientId = os:getEnv("CLIENT_ID"); -configurable string clientSecret = os:getEnv("CLIENT_SECRET"); -configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); -configurable string refreshUrl = os:getEnv("REFRESH_URL"); -configurable string baseUrl = os:getEnv("EP_URL"); - -// Using direct-token config for client configuration -salesforce:ConnectionConfig sfConfig = { - baseUrl, - auth: { - clientId, - clientSecret, - refreshToken, - refreshUrl - } -}; - -public function main() returns error? { - // Create Salesforce client. - salesforce:Client baseClient = check new (sfConfig); - - record {}|error res = baseClient->getByExternalId("Contact", "My_External_Id__c", "102"); - - if res is record {} { - anydata recName = res["FirstName"]; - log:printInfo("Account data received successfully. Account Name : " + recName.toString()); - } else { - log:printError(msg = res.message()); - } -}