Skip to content

Notes about the implementation #3

@gitfvb

Description

@gitfvb

https://github.com/jsforce/jsforce/blob/master/build/jsforce-api-bulk.js

Rough notes about the bulk api implementation

/**
* Class for Bulk API Job
*
* @protected
* @class Bulk~Job
* @extends events.EventEmitter
*
* @param {Bulk} bulk - Bulk API object
* @param {String} [type] - SObject type
* @param {String} [operation] - Bulk load operation ('insert', 'update', 'upsert', 'delete', or 'hardDelete')
* @param {Object} [options] - Options for bulk loading operation
* @param {String} [options.extIdField] - External ID field name (used when upsert operation).
* @param {String} [options.concurrencyMode] - 'Serial' or 'Parallel'. Defaults to Parallel.
* @param {String} [jobId] - Job ID (if already available)
*/

Create a job

var operation = this.operation.toLowerCase();
   if (operation === 'harddelete') { operation = 'hardDelete'; }
   var body = [
     '<?xml version="1.0" encoding="UTF-8"?>',
     '<jobInfo  xmlns="http://www.force.com/2009/06/asyncapi/dataload">',
       '<operation>' + operation + '</operation>',
       '<object>' + this.type + '</object>',
       (this.options.extIdField ?
        '<externalIdFieldName>'+this.options.extIdField+'</externalIdFieldName>' :
        ''),
       (this.options.concurrencyMode ?
        '<concurrencyMode>'+this.options.concurrencyMode+'</concurrencyMode>' :
        ''),
       (this.options.assignmentRuleId ?
         '<assignmentRuleId>' + this.options.assignmentRuleId + '</assignmentRuleId>' :
         ''),
       '<contentType>CSV</contentType>',
     '</jobInfo>'

bulk._request({
     method : 'POST',
     path : "/job",
     body : body,
     headers : {
       "Content-Type" : "application/xml; charset=utf-8"
     },
     responseType: "application/xml"

Create batch instance on job

Get status

return bulk._request({
      method : 'GET',
      path : "/job/" + self.id,
      responseType: "application/xml"
    });
  }).then(function(res) {
    logger.debug(res.jobInfo);
    self.id = res.jobInfo.id;
    self.type = res.jobInfo.object;
    self.operation = res.jobInfo.operation;
    self.state = res.jobInfo.state;
    return res.jobInfo;
  });

List all jobs in batch info

return bulk._request({
      method : 'GET',
      path : "/job/" + self.id + "/batch",
      responseType: "application/xml"
    });

Set status to abort

Close job

POST DATA

return bulk._request({
   method : 'POST',
   path : "/job/" + batch.job.id + "/batch",
   headers: {
     "Content-Type": "text/csv"
   },
   responseType: "application/xml"

Metadata

Metadata

Assignees

No one assigned

    Labels

    developmentSomething that needs to be done

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions