Coder Social home page Coder Social logo

zzhaobraze / salesforce_bulk_client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fronteraconsulting/salesforce_bulk_client

0.0 1.0 0.0 21 KB

SalesforceBulkClient is a Ruby gem which allows for integration with the Salesforce.com Bulk API.

License: MIT License

Ruby 99.26% Shell 0.74%

salesforce_bulk_client's Introduction

SalesforceBulkClient

SalesforceBulkClient is a Ruby gem which allows for integration with the Salesforce.com Bulk API.

Although there are many other gems to choose from for this purpose, this gem offers the following features:

  • JSON is used for all API requests and responses (instead of XML) in order to reduce message size.
  • Splitting data into batches for inserts, updates, and deletes are handled automatically. Batches will be split further if the 10,000,000 character limit per batch would be exceeded.
  • Large sets of data can be processed without pre-loading multiple batches.
  • Connect using the Restforce client instance.

Installation

Add this line to Gemfile:

gem 'salesforce_bulk_client'

And then execute:

$ bundle

Or install it as follows:

$ gem install salesforce_bulk_client

Usage

Instantiate the Bulk API Client

Authentication is done via the Restforce gem:

require 'salesforce_bulk_client'
restforce_client = Restforce.new(
    username:       ENV['SALESFORCE_USERNAME'],
    password:       ENV['SALESFORCE_PASSWORD'],
    security_token: ENV['SALESFORCE_SECURITY_TOKEN'],
    client_id:      ENV['SALESFORCE_OAUTH_CONSUMER_KEY'],
    client_secret:  ENV['SALESFORCE_OAUTH_CONSUMER_SECRET'].to_i,
    host:           ENV['SALESFORCE_HOST'])
bulk_client = SalesforceBulkClient::Client.new(restforce_client)

Inserting records

records = [ { Name: 'Test Account 1' }, { Name: 'Test Account 2' } ]
result = bulk_client.insert(sobject, records)

Upserting records

records = [ { Id: '00136000014tyyF', Name: 'Test Account 1' }, { Name: 'Test Account 2' } ]
result = bulk_client.upsert(sobject, records, 'Id')

Updating records

records = [ { Id: '00136000014tyyF', Name: 'Test Account 1' }, { Id: '00136000014tyyP', Name: 'Test Account 2' } ]
result = bulk_client.update(sobject, records)

Deleting records

records = [ { Id: '00136000014tyyF' }, { Id: '00136000014tyyP' } ]
result = bulk_client.delete(sobject, records)

Query records

result = bulk_client.query('Account', "select Id, Name from Account where Id = '00136000014tyyF'", true)

Process batches without pre-loading

result = bulk_client.query('Account', "select Id, Name from Account where Id = '00136000014tyyF'", false)
bulk_client.job_from_id(result.id).each_batch do |batch, batch_results|
  # Add batch-level processing logic here
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/FronteraConsulting/salesforce_bulk_client.

salesforce_bulk_client's People

Contributors

zzhaobraze avatar

Watchers

James Cloos 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.