Module that helps handle a salesforce connection and all the fun mess that comes with salesforce.
npm install dread-steed --save
pass this config object into dread steed
var config = {
maxConnDuration:10.000,
maxRetries:2,
silent:true, // silence dreadsteed log messages Defaults to false
errorTypes:['INVALID_SESSION_ID','INVALID_LOGIN','DUPLICATE_VALUE','SERVER_UNAVAILABLE','REQUEST_LIMIT_EXCEEDED'],
maxEventListeners:100,
salesforce: {
Username: '[email protected]',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',//login.salesforce.com
SecurityToken: 'thisisasecuritytoken',
}
};
For handling of multiple saleforce connections.
NOTE: Api user will switch if it hits an api limit and throws REQUEST_LIMIT_EXCEEDED or SERVER_UNAVAILABLE
otherwise it will just use the 1 api user
var config = {
maxConnDuration:10.000,
maxRetries:2,
silent:true, // silence dreadsteed log messages Defaults to false
errorTypes:['INVALID_SESSION_ID','INVALID_LOGIN','DUPLICATE_VALUE','SERVER_UNAVAILABLE','REQUEST_LIMIT_EXCEEDED'],
maxEventListeners:100,
salesforce: [
{
Username: '[email protected]',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',//login.salesforce.com
SecurityToken: 'thisisasecuritytoken',
},
{
Username: '[email protected]',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',//login.salesforce.com
SecurityToken: 'thisisasecuritytoken',
},
{
Username: '[email protected]',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',//login.salesforce.com
SecurityToken: 'thisisasecuritytoken',
},
{
Username: '[email protected]',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',//login.salesforce.com
SecurityToken: 'thisisasecuritytoken',
}
]
};
Optional if you want to handle errors and or log then in your own way
var errorCallback = function(err){
//err - object
};
If you want to use callbacks for more than just error handling, you can optionally pass in an object with a callback for error handling and a callback for when the salesforce connection is established or re-established.
var errorCallback = function(err){
//err - object
};
var connectionCallback = function(conn){
//conn - jsforce connection object
}
var callbacks = {
onError: errorCallback,
onConnection: connectionCallback
};
var DreadSteed = require('dread-steed');
var dreadSteed = new DreadSteed(config, errorCallback); //OR new DreadSteed(config, callbacks);
var yourSalesForceQueryHere = "SELECT id, Name FROM Things WHERE id = '1' ";
getAllTheThings = function(id){
return dreadSteed.getConnection().then(function(conn){
//use the connection!
return conn.queryAsync(yourSalesForceQueryHere);
}).catch(function(err){
log.error(err);
throw err;
});
}
updateAllTheThings = function( updateObj, name ) {
return dreadSteed.getConnection().then(function(conn){
return conn.updateAsync( name, updateObj ).then(function( res ){
return res;
}).catch(function( err ){
log.error(err);
throw err;
});
}).catch(function(err){
log.error(err);
throw err;
});
}
createAllTheThings = function( newObj, name ) {
return dreadSteed.getConnection().then(function(conn){
return conn.createAsync(name, newObj).then(function(res) {
return res;
}).catch(function(err) {
log.error(err);
throw err;
});
}).catch(function(err) {
log.error(err);
throw err;
});
}
deleteTheThing = function ( Id ) {
return dreadSteed.getConnection()
.then(function ( conn ) {
return conn.deleteAsync( 'Things', Id );
}).catch(function(err) {
log.error(err);
throw err;
});
};
- 0.0.1 Initial release
- 0.0.2
- 0.0.3
- 0.0.4 Config changes
- 0.0.5 copyright added updated readme
- 0.0.6 error handle callback
- 0.0.7 removed unused salesforce config from README.md
- 0.0.8 allow optional callback for successful salesforce connections/re-connections
- 0.0.9 allow multiple api users to switch to when api limits are hit or server unavailable happens
- 0.0.10 Code cleanup and package json updates
- 0.0.11 changed to MIT license added LICENSE file
- 0.1.0 added a silent option to ignore console logs
- 0.1.1 Removed MomentJS dependency, Removed Lodash library. Moved to individual needed functions. Add Row lock error to retry logic on queries.