Giter Club home page Giter Club logo

Comments (4)

pramodya1994 avatar pramodya1994 commented on May 24, 2024

As mentioned in bulk API documentation [1],
For jobs with a contentType of CSV, XML is used as the response format except in the case of bulk query results, which are returned in CSV.
To ensure that you retrieve responses in JSON, create a job with a contentType of JSON and use JSON for your batch payloads.
To ensure that you retrieve responses in XML, create a job with a contentType of XML or CSV and use the same format for your batch payloads.

Because of this reason we are getting XML responses for CSV and XML cases. Then we will convert that XML to JSON and return JSON responses in ballerina salesforce bulk API.
For JSON case we will get responses as JSON and return those as it is.

[1] https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/async_api_headers_content_type.htm

from ballerina-integrator.

pramodya1994 avatar pramodya1994 commented on May 24, 2024

Blocker in ballerina-lang: ballerina-platform/ballerina-lang#16965

from ballerina-integrator.

pramodya1994 avatar pramodya1994 commented on May 24, 2024

Salesforce bulk client can be created as follows using Salesforce client.

import sfdc46;

string epUrl = "https://<REGION>.salesforce.com";

sfdc46:SalesforceConfiguration sfConfig = {
    baseUrl: epUrl,
    clientConfig: {
        accessToken: ACCESS_TOKEN,
        refreshConfig: {
            clientId: CLIENT_ID,
            clientSecret: CLIENT_SECRET,
            refreshToken: REFRESH_TOKEN,
            refreshUrl: "https://login.salesforce.com/services/oauth2/token"
        }
    }
};

// Create salesforce client.
sfdc46:Client sfClient = new(sfConfig);
// Create salesforce bulk client.
sfdc46:SalesforceBulkClient sfBulkClient = sfClient->createSalesforceBulkClient();

Following operator clients are available in the Salesforce bulk client.

  • CSV
    • CSV insert operator
    • CSV upsert operator
    • CSV update operator
    • CSV delete operator
    • CSV query operator
  • JSON
    • JSON insert operator
    • JSON upsert operator
    • JSON update operator
    • JSON delete operator
    • JSON query operator
  • XML
    • XML insert operator
    • XML upsert operator
    • XML update operator
    • XML delete operator
    • XML query operator

Operator can be created as follows.

// Create bulk JSON uploader object. This will create a job to upload JSON contacts as batches.
sfdc46:JsonInsertOperator | sfdc46:SalesforceError jsonInsertOperator = sfBulkClient->createJsonInsertOperator("Contact");

After creating an operator, salesforce job will be created to perform the operation. Then we can add batches to the job
as follows.

// Contacts to be inserted.
json contacts = [
    {
        description: "Created from Bulk API",
        FirstName: "Morne",
        LastName: "Morkel",
        Title: "SE",
        Phone: "0442226670",
        Email: "[email protected]",
        My_External_Id__c: "201"
    },
    {
        description: "Created from Bulk API",
        FirstName: "Andi",
        LastName: "Flower",
        Title: "SE",
        Phone: "0442216170",
        Email: "[email protected]",
        My_External_Id__c: "202"
    }
];

// Upload json as a batch.
sfdc46:Batch | sfdc46:SalesforceError batchDetails = jsonInsertOperator->upload(contacts);

Get batch details, batch request details and batch results can be done as follows.

// Get details of first batch.
sfdc46:Batch | sfdc46:SalesforceError batchInfo = jsonInsertOperator->getBatchInfo(BatchID);

// Get batch request details.
json | sfdc46:SalesforceError batchRequestDetails = jsonInsertOperator->getBatchRequest(BatchID);

// Get batch results.
json | sfdc46:SalesforceError batchResults = jsonInsertOperator->getBatchResults(BatchID);

Get job details, Close or Abort job and get details about all batches of this job can be done as follows.

// Get job details.
sfdc46:Job | sfdc46:SalesforceError jobDetails = jsonInsertOperator->getJobInfo();

// Close the job.
sfdc46:Job | sfdc46:SalesforceError jobClosedDetails = jsonInsertOperator->closeJob();

// Abort the job.
sfdc46:Job | sfdc46:SalesforceError jobAbortDetails = jsonInsertOperator->abortJob();

// Get details about all batches of this job.
sfdc46:BatchInfo | sfdc46:SalesforceError allBatchesInfo = jsonInsertOperator->getAllBatches();

from ballerina-integrator.

pramodya1994 avatar pramodya1994 commented on May 24, 2024

Fixed in ballerina-platform/module-ballerinax-sfdc#60

from ballerina-integrator.

Related Issues (20)

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.