Nearly four years ago, I first wrote about ForceTK, the JavaScript toolkit for calling the Force.com REST API from Visualforce pages, external web sites and hybrid mobile apps. Since then, ForceTK has become part of every Force.com client-side web developer’s toolbox.

Although the Force.com REST API makes accessing data in Salesforce very straightforward, it is limited to inserting, updating and deleting a single record at a time. The SOAP API is able to manipulate larger sets of records, but is more complex to work with. The Bulk API, on the other hand is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, insert, update, upsert, or delete thousands of records asynchronously by submitting batches which are processed in the background by Salesforce.

Although the Bulk API is indeed ‘based on REST principles’, it is very different from the REST API itself. Rather than operating on records in Salesforce, clients create asynchronous jobs, upload records in batches, and periodically check for job status. Although data can be uploaded in CSV or XML format, clients exchange XML messages in the ‘control plane’.

A recent issue filed against Force.com prompted me to investigate whether it would be possible to call the Bulk API from JavaScript, uploading files with thousands of records to insert, update or delete, or executing bulk queries.

With the help of a public domain JavaScript XML Object Notation (JXON) implementation in the Ratotask project, it took just a few hours to implement a first cut of ‘BulkTK’, a Force.com Bulk API JavaScript toolkit.

BulkTK

BulkTK extends ForceTK by adding methods to the ForceTK client object. After initializing a ForceTK client with a session ID, you can create a Bulk API job,

add one or more batches of records,

close the job,

check batch status,

and retrieve results,

which, for a CSV job, are in the form

A sample Visualforce page demonstrates bulk query, insert, update, upsert and delete for both CSV and XML data.

As of this writing, BulkTK should be considered ‘early Alpha’ quality, but brave (‘foolhardy?’) developers are invited to take it for a spin (in a Sandbox or Developer Edition, please!) and report back their findings. Leave a comment here, file an issue or, best of all, fork ForceTK and submit a pull request!

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS