Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // populate env vars
- require('dotenv').config();
- const nforce = require('nforce');
- // create the connection with the Salesforce connected app
- const org = nforce.createConnection({
- clientId: process.env.CLIENT_ID,
- clientSecret: process.env.CLIENT_SECRET,
- redirectUri: process.env.CALLBACK_URL,
- mode: 'single'
- });
- // authenticate and return OAuth token
- org.authenticate({ username: process.env.USERNAME, password: process.env.PASSWORD, securityToken: process.env.SECURITY_TOKEN })
- .then(resp => {
- console.log('Successfully logged in! Cached Token: ' + org.oauth.access_token);
- // execute the query
- org.query({ query: 'select id, name from user limit 5' })
- .then(resp => {
- if(resp.records) {
- // output the account names
- for (i=0; i<resp.records.length;i++) {
- console.log(resp.records[i].get('name'));
- }
- }
- })
- .catch(err => {
- console.log(err);
- });
- })
- .catch(err => {
- console.log(err);
- });
Add Comment
Please, Sign In to add comment