Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(`itemsLikeCreateResult['likedItem']: ${itemsLikeCreateResult as any['likedItem']}`);
}
(async () => {
const query2: sf.QueryResult =
await (salesforceConnection.query("SELECT Id, Name FROM User") as Promise>);
console.log("Query Promise: total in database: " + query2.totalSize);
console.log("Query Promise: total fetched : " + query2.records[0]);
await testAnalytics(salesforceConnection);
await testChatter(salesforceConnection);
await testMetadata(salesforceConnection);
await testExecuteAnonymous(salesforceConnection);
})();
const oauth2 = new sf.OAuth2({
// you can change loginUrl to connect to sandbox or prerelease env.
// loginUrl : 'https://test.salesforce.com',
clientId: '',
clientSecret: '',
redirectUri: ''
});
oauth2.getAuthorizationUrl({ scope: 'api id web' });
const job = salesforceConnection.bulk.createJob("Account", "insert");
const batch = job.createBatch();
batch.execute(undefined);
batch.on("queue", (batchInfo) => { // fired when batch request is queued in server.
console.log('batchInfo:', batchInfo);
const batchId = batchInfo.id;
const jobId = batchInfo.jobId;
});
function getOAuth2() {
return new jsforce.OAuth2({
// you can change loginUrl to connect to sandbox or prerelease env.
// loginUrl : 'https://test.salesforce.com',
clientId: config.app.key,
clientSecret: config.app.secret,
redirectUri: config.app.callbackURL
});
}
// ==============================================
// Load libraries
// ==============================================
var dotenv = require('dotenv').config(); // necessary if running via 'node app.js' instead of 'heroku local'
var jsforce = require('jsforce'); // salesforce client
var express = require('express'); // nodejs de-facto web server
var exphbs = require('express-handlebars'); // for html templating responses
var path = require('path'); // utility for parsing and formatting file paths
// ==============================================
// Salesforce OAuth Settings (reusable)
// ==============================================
var sf_oauth2 = new jsforce.OAuth2({
loginUrl : process.env.OAUTH_SALESFORCE_LOGIN_URL,
clientId : process.env.OAUTH_SALESFORCE_CLIENT_ID,
clientSecret : process.env.OAUTH_SALESFORCE_CLIENT_SECRET,
redirectUri : process.env.OAUTH_SALESFORCE_REDIRECT_URI
});
// ==============================================
// Configure web app to respond to requests
// ==============================================
var app = express();
app.engine( 'handlebars', exphbs( { defaultLayout: 'main' } ) );
app.set( 'view engine', 'handlebars' );
app.set( 'json spaces', 4 ); // pretty print json
constructor (options) {
if (!options) throw new Error('Need options')
let oauth2 = oauth2model
oauth2.loginUrl = options.loginUrl || 'https://login.salesforce.com'
Object.assign(this, options)
this.connection = new jsforce.Connection({
oauth2: new jsforce.OAuth2(oauth2),
instanceUrl: options.instanceUrl,
refreshToken: Crypto.decrypt(options.refreshToken)
})
this.connection.on('refresh', (accessToken, res) => {
console.log(`[${this.orgId}] Refreshing Oauth2 token..`)
this.connection.accessToken = accessToken
})
}
router.get('/add/:type', (req, res) => {
let oauth2 = oauth2model
let loginUrl = 'https://login.salesforce.com'
if (req.params.type === 'sandbox') loginUrl = 'https://test.salesforce.com'
oauth2.loginUrl = loginUrl
res.redirect(new jsforce.OAuth2(oauth2).getAuthorizationUrl({ scope: 'api refresh_token' }))
})
function createConnection(instance: string, session: Session): Connection {
const { oauth2, ...tokens } = session;
return new Connection({
...tokens,
instanceUrl: instance,
oauth2: new OAuth2(oauth2),
});
}
getOAuthClient(orgType) {
var loginUrl = (orgType == 'production') ? 'https://login.salesforce.com' : 'https://test.salesforce.com';
var oauth2 = new jsforce.OAuth2({
loginUrl : loginUrl,
clientId : CLIENT.SFDC_CLIENT_ID,
clientSecret : CLIENT.SFDC_CLIENT_SECRET,
redirectUri : CLIENT.SFDC_CALLBACK_URL + '&orgType=' + orgType
});
return oauth2;
}
/**