Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes about the implementation #3

Open
gitfvb opened this issue May 12, 2020 · 0 comments
Open

Notes about the implementation #3

gitfvb opened this issue May 12, 2020 · 0 comments
Labels
development Something that needs to be done

Comments

@gitfvb
Copy link
Collaborator

gitfvb commented May 12, 2020

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"
@gitfvb gitfvb added the development Something that needs to be done label May 12, 2020
@gitfvb gitfvb added this to the Finish Salesforce BULK API milestone May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Something that needs to be done
Projects
None yet
Development

No branches or pull requests

1 participant