Giter Site home page Giter Site logo

module-ballerinax-sfdc's Introduction

Ballerina Salesforce Connector

Build codecov Trivy GitHub Last Commit GraalVM Check License

Salesforce Sales Cloud is a widely used CRM software provided by Salesforce Inc. Sales Cloud offers various APIs that enable developers to extend and integrate the platform with other applications, services, and systems.

Ballerina Salesforce connector utilizes the Salesforce REST API, Bulk API, Bulk API V2, APEX REST API, and SOAP API for convenient data manipulation. The Salesforce connector allows you to perform CRUD operations for SObjects, query using SOQL, search using SOSL, and describe SObjects and organizational data through the Salesforce REST API and SOAP API. Also, it supports accessing APEX endpoints using the APEX REST API and adding bulk data jobs and batches via the Salesforce Bulk and Bulk V2 APIs. For more information about configuration and operations, go to the module(s).

  • salesforce
    • Perform Salesforce operations programmatically through the Salesforce REST API. Users can perform CRUD operations for SObjects, query using SOQL, search using SOSL and describe SObjects and organizational data. Accessing APEX endpoints and Bulk V2 jobs and operations can also be done using this module.
  • salesforce.bulk
    • Perform Salesforce bulk operations programmatically through the Salesforce Bulk API. Users can perform CRUD operations in bulk for Salesforce.
  • salesforce.soap
    • Perform Salesforce operations programmatically through the Salesforce SOAP API, which is not supported by the Salesforce REST API. The connector is comprised of limited operations on SOAP API.

Setup guide

  1. Create a Salesforce account with the REST capability.

  2. Go to Setup --> Apps --> App Manager

    Setup Side Panel
  3. Create a New Connected App.

    Create Connected Apps Create Connected Apps
  4. After the creation user can get consumer key and secret through clicking on the Manage Consume Details button.

    Consumer Secrets
  5. Next step would be to get the token.

    • Log in to salesforce in your prefered browser and enter the following url.
https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<CONSUMER_KEY>&redirect_uri=<REDIRECT_URL>
  • Allow access if an alert pops up and the browser will be redirected to a Url like follows.

    https://login.salesforce.com/?code=<ENCODED_CODE>
    
  • The code can be obtained after decoding the encoded code

  1. Get Access and Refresh tokens
    • Following request can be sent to obtain the tokens.

      curl -X POST https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<CONSUMER_KEY>&client_secret=<CONSUMER_SECRET>&redirect_uri=https://test.salesforce.com/
      
    • Tokens can be obtained from the response.

Quickstart

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

Step 1: Import connector

Import the ballerinax/salesforce package into the Ballerina project.

import ballerinax/salesforce;

Step 2: Create a new connector instance

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

salesforce:ConnectionConfig config = {
    baseUrl: baseUrl,
    auth: {
        clientId: clientId,
        clientSecret: clientSecret,
        refreshToken: refreshToken,
        refreshUrl: refreshUrl
    }
};

salesforce:Client salesforce = new(config);

Step 3: Invoke connector operation

  1. Now you can utilize the available operations. Note that they are in the form of remote operations.

Following is an example on how to create a record using the connector.

salesforce:CreationResponse response = check 
    baseClient->create("Account", {
                        "Name": "IT World",
                        "BillingCity": "New York"
                        });
  1. To integrate the Salesforce listener into your Ballerina application, update the .bal file as follows:

Create an instance of salesforce:Listener using your Salesforce username, password, security token, and subscribe channel name.

import ballerinax/salesforce;

salesforce:ListenerConfig listenerConfig = {
    auth: {
        username: "username",
        password: "password" + "security token"
    }
};
listener salesforce:Listener eventListener = new (listenerConfig);

Implement the listener’s remote functions and specify the channel name to be subscribed to as the service name.

import ballerina/io;
import ballerinax/salesforce;

salesforce:ListenerConfig listenerConfig = {
    auth: {
        username: "username",
        password: "password" + "security token"
    }
};
listener salesforce:Listener eventListener = new (listenerConfig);

service "/data/ChangeEvents" on eventListener {
    remote function onCreate(salesforce:EventData payload) {
        io:println("Created " + payload.toString());
    }

    remote isolated function onUpdate(salesforce:EventData payload) {
        io:println("Updated " + payload.toString());
    }

    remote function onDelete(salesforce:EventData payload) {
        io:println("Deleted " + payload.toString());
    }

    remote function onRestore(salesforce:EventData payload) {
        io:println("Restored " + payload.toString());
    }
}
  1. Integrate custom SObject types

To seamlessly integrate custom SObject types into your Ballerina project, you have the option to either generate a package using the Ballerina Open API tool or utilize the ballerinax/salesforce.types module. Follow the steps given here based on your preferred approach.

import ballerinax/salesforce.types;

public function main() returns error? {
    types:AccountSObject accountRecord = {
        Name: "IT World",
        BillingCity: "New York"
    };

    salesforce:CreationResponse res = check salesforce->create("Account", accountRecord);
}
  1. Use following command to compile and run the Ballerina program.
bal run

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 - How to employ REST API of Salesforce to carryout various tasks.

  2. Salesforce Bulk API use cases - How to employ Bulk API of Salesforce to execute Bulk jobs.

  3. Salesforce Bulk v2 API use cases - How to employ Bulk v2 API to execute an ingest job.

  4. Salesforce APEX REST API use cases - How to employ APEX REST API to create a case in Salesforce.

Report Issues

To report bugs, request new features, start new discussions, view project boards, etc., go to the Ballerina library parent repository.

Building from the source

Setting up the prerequisites

  1. Download and install Java SE Development Kit (JDK) version 17. You can install either OpenJDK or Oracle JDK.

    Note: Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK.

  2. Download and install Ballerina Swan Lake

Building the source

Execute the commands below to build from the source.

  1. To build Java dependency
    ./gradlew build
    
    • To build the package:
    bal build ./ballerina
    
    • To run tests after build:
    bal test ./ballerina
    

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To debug package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  5. To debug with the Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  6. Publish the generated artifacts to the local Ballerina Central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  7. Publish the generated artifacts to the Ballerina Central repository:

    ./gradlew clean build -PpublishToCentral=true

Contributing to Ballerina

As an open source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

module-ballerinax-sfdc's People

Contributors

sahanhe avatar erandiganepola avatar aneeshafedo avatar aashikam avatar lakshanss avatar sachinira avatar ballerina-bot avatar thishanilucas avatar abeykoon avatar chuhaa avatar biruntha avatar ldclakmal avatar nipunaranasinghe avatar muthulee avatar pramodya1994 avatar kasun-indrasiri avatar sanduds avatar nipunayf avatar niveathika avatar kasthuriraajan avatar azeemmuzammil avatar rolandhewage avatar keerthu avatar bhashinee avatar maryamzi avatar dushaniw avatar sknuwantissera avatar maheshika avatar keizer619 avatar indikasampath2000 avatar

Stargazers

Nuvindu Nirmana avatar M.M.H.Thaksarani avatar Charuka Muthukumarana avatar Sakith Deepna Wijenanda avatar Krishnaanantham Samahithan avatar  avatar Manulji Ranasinghe avatar  avatar  avatar Rukshan Fernando  avatar niamatmarjan avatar Kanishka Hewageegana avatar Dhanuja Thishakya Samaranayake avatar Hanaanee Hana avatar HERATH H.M.T.K. avatar Lakshani Rasa avatar Pasindu Rathnayaka avatar Nethmal Wijesinghe avatar  avatar Siriwardhana S.M.C.R avatar Sahan vishwajith avatar  avatar Rafshan Rakeeb avatar  avatar  avatar Dakshina Ranmal avatar Safnas Kaldeen avatar Piumini Kaveesha Ranasinghe avatar Mohamed Aathif avatar Haritha Mihimal Wilwala Arachchi avatar Sithika Guruge avatar Sanjula Gathsara avatar Anupa Perera avatar Deshitha Gallage avatar Shavin Anjitha Chandrawansha avatar Ravin Dulanjana Fernando avatar Thisura Gallage avatar Thenujan Nagaratnam avatar Themira Chathumina avatar Wenuka Somarathne avatar Hiruna Harankahadeniya avatar Dumindu Sameendra avatar Thushara Piyasekara avatar  avatar Sachin Akash avatar Indrajith Madhumal avatar Dinura Dissanayake avatar e17100 avatar Gabilan Ganeshwaran avatar Shafreen Anfar avatar Nipuna Madhushan avatar  avatar Waruna Lakshitha avatar Kalaiyarasi Ganeshalingam avatar  avatar Dulmina Renuke avatar Malintha Ranasinghe avatar Mindula Rowel avatar prakanth avatar Lakshan Weerasinghe avatar  avatar  avatar Sasindu Alahakoon avatar Ayesh Almeida avatar Hasitha Aravinda avatar Hinduja Balasubramaniyam avatar Kaumini Gunasinghe avatar  avatar Chamupathi Gigara Hettige avatar Tharindu Jayathilake avatar  avatar  avatar Anjana Supun avatar Yasith Deelaka avatar Sarani Mendis avatar Tharindu Udupitiya avatar Sachini Samson avatar manuranga perera avatar  avatar Poorna Gunathilaka avatar Ushira Karunasena avatar Dulaj Dilshan avatar Gimantha Bandara avatar Chiran Fernando avatar Kavith Thiranga Lokuhewage avatar Kanushka Gayan avatar Anuruddha Lanka Liyanarachchi avatar  avatar Anupama Pathirage avatar Sumudu Nissanka avatar  avatar Heshan Padmasiri avatar  avatar Miran Kurukulasuriya avatar Nadeeshan Dissanayake avatar Krishnananthalingam Tharmigan avatar Tharindu Weerasinghe avatar Madusha Gunasekera avatar Dilan Sachintha Nayanajith avatar Danesh Kuruppu avatar

Watchers

Nirmal Fernando avatar Yasith Tharindu avatar Kasun Indrasiri avatar Isuru Udana Loku Narangoda avatar James Cloos avatar Kasun Gajasinghe avatar Maheeka Jayasuriya avatar Nadeeshaan Gunasinghe avatar Sasikala Kottegoda avatar Manuri Amaya Perera avatar Tharindu Wijewardane avatar Kevin Ratnasekera avatar Maninda Edirisooriya avatar Dhananjaya [Danje] avatar Kavith Thiranga Lokuhewage avatar  avatar manuranga perera avatar Vinod Kavinda avatar Shakila avatar Rukshan Perera avatar Shankar avatar Sameera Jayasoma avatar Afkham Azeez avatar Lakmal Warusawithana avatar Amila Mahaarachchi avatar  avatar Pamod Sylvester avatar Grainier Perera avatar Eranda Rajapakshe avatar Shan Mahanama avatar Waruna Lakshitha avatar Hemika Kodikara avatar  avatar Sajith Ravindra avatar Chandana Napagoda avatar Fathima Dilhasha avatar Vijitha Ekanayake avatar  avatar Chanaka Fernando avatar  avatar Rajith avatar Ruvinda Dhambarage avatar Shavantha Weerasinghe avatar Sohani Weerasinghe avatar  avatar  avatar  avatar Dhanushka Madushan avatar Nuwan Wimalasekara avatar Mohanadarshan V avatar  avatar Yasassri Ratnayake avatar Chathura Ekanayake avatar Sanjeewa Malalgoda avatar  avatar Chamil Elladeniya avatar Danesh Kuruppu avatar Anoukh Jayawardena avatar Nipuna Marcus avatar Irunika Weeraratne avatar Gimantha Bandara avatar Nisrin avatar Malsha Ranawaka avatar Manorama Perera avatar Sharon David avatar Anuruddha Lanka Liyanarachchi avatar Imesh Chandrasiri avatar Frank avatar  avatar Milan Perera avatar Kalaiyarasi Ganeshalingam avatar  avatar Kavitha avatar Pranavan avatar Anupama Pathirage avatar Chamupathi Gigara Hettige avatar Dinuksha Ishwari avatar Irushi Liyanage avatar Asma Jabir avatar Buddhi Kothalawala avatar  avatar  avatar Samuel Mervyn Gnaniah avatar  avatar Kajendran Alagaratnam avatar Sumudu Nissanka avatar  avatar Suleka Helmini avatar Niron Rasanjana avatar  avatar Ushira Karunasena avatar Sean P. Myrick V19.1.7.2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.