Back to pre-built integrations

Data about products, customers, and sales transactions are often scattered across various systems, databases, and business units. Extracting this information and integrating it into Salesforce is essential for a unified view. Ballerina, with its rich set of connectors and data handling capabilities, can connect to multiple data sources and fetch data in any format. By linking disparate data, Ballerina aids in enriching Salesforce with relevant information, making it the single source for all customer information.

The example below demonstrates how to create Salesforce products based on newly added MySQL records.

Flow Diagram
Copy
import ballerinax/mysql;
import ballerinax/salesforce as sf;

type Product record {
    string Name;
    string Product_Unit__c;
    string CurrencyIsoCode;
};

type ProductRecieved record {
    string name;
    string unitType;
    string currencyISO;
    string productId;
};

const int HEADINGS_ROW = 1;

//mySQL configuration parameters
configurable int port = ?;
configurable string host = ?;
configurable string user = ?;
configurable string database = ?;
configurable string password = ?;

// Salesforce configuration parameters
configurable string salesforceAccessToken = ?;
configurable string salesforceBaseUrl = ?;

sf:Client salesforce = check new ({
    baseUrl: salesforceBaseUrl,
    auth: {
        token: salesforceAccessToken
    }
});

public function main() returns error? {
    mysql:Client mysql = check new (host, user, password, database, port);
    stream<ProductRecieved, error?> streamOutput = mysql->query(
        `SELECT name, unitType, currencyISO, productId FROM products WHERE processed = false`);
    ProductRecieved[] productsRecieved = check from ProductRecieved items in streamOutput
        select items;
    foreach ProductRecieved prductRecieved in productsRecieved {
        Product product = {
            Name: prductRecieved.name,
            Product_Unit__c: prductRecieved.unitType,
            CurrencyIsoCode: prductRecieved.currencyISO
        };
        _ = check salesforce->create("Product2", product);
        _ = check mysql->execute(
            `UPDATE products SET processed = true WHERE productId = ${prductRecieved.productId}`);
    }
}
Sequence Diagram