Guest User

Untitled

a guest
May 2nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // populate env vars
  2. require('dotenv').config();
  3.  
  4. const nforce = require('nforce');
  5.  
  6. // create the connection with the Salesforce connected app
  7. const org = nforce.createConnection({
  8.   clientId: process.env.CLIENT_ID,
  9.   clientSecret: process.env.CLIENT_SECRET,
  10.   redirectUri: process.env.CALLBACK_URL,
  11.   mode: 'single'
  12. });
  13.  
  14. // authenticate and return OAuth token
  15. org.authenticate({ username: process.env.USERNAME, password: process.env.PASSWORD, securityToken: process.env.SECURITY_TOKEN })
  16.   .then(resp => {
  17.     console.log('Successfully logged in! Cached Token: ' + org.oauth.access_token);
  18.     // execute the query
  19.     org.query({ query: 'select id, name from user limit 5' })
  20.       .then(resp => {
  21.         if(resp.records) {
  22.           // output the account names
  23.           for (i=0; i<resp.records.length;i++) {
  24.             console.log(resp.records[i].get('name'));
  25.           }
  26.         }
  27.       })
  28.       .catch(err => {
  29.         console.log(err);
  30.       });
  31.   })
  32.   .catch(err => {
  33.     console.log(err);
  34.   });
Add Comment
Please, Sign In to add comment