How to use the jsforce.Connection function in jsforce

To help you get started, we’ve selected a few jsforce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Plazmaz / leaky-repo / web / js / salesforce.js View on Github external
function sfQuery(queryString, success, error){
    let conn = new jsforce.Connection();
    // Security Risk!
    conn.login('username@example.com', 'salesforcepassword', function(err, res) {
        if (err) {
            error(err);
            console.error(err);
        }
        conn.query('SELECT Id FROM User', function(err, res) {
            if (err) {
                error(err);
                console.error(err);
            }
            success(res);
        });
    });
}
github wadewegner / sfdx-waw-plugin / commands / auth_username_login.js View on Github external
run(context) {
      const username = context.flags.username;
      const password = context.flags.password;
      let instanceUrl = context.flags.instanceurl;

      if (!instanceUrl) {
        instanceUrl = 'https://login.salesforce.com';
      }

      const saveAsDefault = false;

      const conn = new jsforce.Connection({
        // you can change loginUrl to connect to sandbox or prerelease env.
        loginUrl: instanceUrl
      });

      conn.login(username, password, (err, userInfo) => {
        if (err) {
          return console.error(err);
        }

        const orgSaveData = [];
        orgSaveData.orgId = userInfo.organizationId;
        orgSaveData.accessToken = conn.accessToken;
        orgSaveData.instanceUrl = conn.instanceUrl;
        orgSaveData.username = username;
        orgSaveData.loginUrl = instanceUrl;
github douglascayers / sfdc-swag-level-platform-events-demo / app.js View on Github external
app.get( '/oauth2/callback', function( req, res ) {

    // in testing, browsers would send a duplicate request after 5 seconds
    // if this redirection did not respond in time.
    // to avoid having a duplicate request we must tell the browser to wait longer
    // https://github.com/expressjs/express/issues/2512
    req.connection.setTimeout( 1000 * 60 * 10 ); // ten minutes

    // initialize salesforce client for making the oauth authorization request
    var sfClient = new jsforce.Connection({
        oauth2 : sf_oauth2,
        version : process.env.SALESFORCE_API_VERSION
    });

    // salesforce oauth authorize request to get access token
    sfClient.authorize( req.query.code, function( err, userInfo ) {

        if ( err ) {

            handleError( err, res );

        } else {

            subscribeToEvents( sfClient, res );

        }
github wadewegner / sfdx-waw-plugin / src / commands / waw / auth / username / login.ts View on Github external
public async run(): Promise {
    const username = this.flags.username;
    let password = this.flags.password;
    let instanceUrl = this.flags.instanceurl;

    if (!instanceUrl) {
      instanceUrl = 'https://login.salesforce.com';
    }

    if (!password) {
      password = await this.ux.prompt(`password for ${username}`, { type: 'mask' });
    }

    const conn = new jsforce.Connection({
      // you can change loginUrl to connect to sandbox or prerelease env.
      loginUrl: instanceUrl
    });

    await conn.login(username, password);

    const accessTokenOptions = {
      accessToken: conn.accessToken,
      instanceUrl: conn.instanceUrl,
      loginUrl: instanceUrl,
      orgId: getString(conn, 'userInfo.organizationId')
    };

    const auth = await AuthInfo.create({ username, accessTokenOptions });
    await auth.save();
github futurice / futurice-super / jsforce_testing.js View on Github external
var credentials = require('./salesforce-credentials.js');
var jsforce = require('jsforce');

var conn = new jsforce.Connection({});

conn.login(credentials.user, credentials.passwordtoken, function(err, userInfo) {
  if (err) { return console.error(err); }

  console.log("Bearer " + conn.accessToken);
  
  console.log(conn.instanceUrl);

  console.log("User ID: " + userInfo.id);
  console.log("Org ID: " + userInfo.organizationId);
});
github douglascayers / sfdc-swag-level-platform-events-demo / app.js View on Github external
app.get( '/publish', function( req, res ) {

    console.log( 'publishing new event...' );

    var sfClient = new jsforce.Connection({
        instanceUrl : req.query.instanceUrl,
        accessToken : req.query.accessToken,
        version : req.query.version
    });

    sfClient.sobject( 'Swag_Level__e' ).create({

        'Level__c' : 'Low'

    }).then( function( result ) {

        console.log( result );
        res.redirect( '/subscribe?accessToken=' + sfClient.accessToken + '&instanceUrl=' + sfClient.instanceUrl );

    }).catch( function( err ) {
github celador / ForceCode / src / services / fcConnectionService.ts View on Github external
.then(orgInf => {
          service.currentConnection = service.addConnection(orgInf, true);
          if (!service.currentConnection) {
            return Promise.reject('Error setting up connection');
          }
          vscode.window.forceCode.config = readConfigFile(orgInf.username);

          const sfdxPath = path.join(
            operatingSystem.getHomeDir(),
            '.sfdx',
            orgInf.username + '.json'
          );
          const refreshToken: string = fs.readJsonSync(sfdxPath).refreshToken;
          service.currentConnection.connection = new jsforce.Connection({
            oauth2: {
              clientId:
                service.currentConnection.orgInfo.clientId || 'SalesforceDevelopmentExperience',
            },
            instanceUrl: service.currentConnection.orgInfo.instanceUrl,
            accessToken: service.currentConnection.orgInfo.accessToken,
            refreshToken: refreshToken,
            version:
              vscode.window.forceCode &&
              vscode.window.forceCode.config &&
              vscode.window.forceCode.config.apiVersion
                ? vscode.window.forceCode.config.apiVersion
                : vscode.workspace.getConfiguration('force')['defaultApiVersion'],
          });

          if (service.currentConnection.connection) {
github rajaraodv / react-redux-blog-vf / routes / posts.js View on Github external
var express = require('express');
var router = express.Router();
var jsforce = require('jsforce');
var conn = new jsforce.Connection({
  serverUrl: 'https://ltng1-dev-ed.my.salesforce.com',
  sessionId: '00Di0000000JEm3!AQ4AQEoB90cYo66ZD8DLTaegtPMrnt3LqoUHaKnRh1uP.mU8cAlJudaqx_jJhASRVx4pcPgCLwWOjRTu2fRrLIR6DgBYciDJ'
});



router.get('/posts', function(req, res, next) {
  var q = req.query.query;
  conn.query(q, function(err, result) {
    if (err) {
      return res.status(400).json(err);
    }
    res.json(result);
  });
});
github postlight / glide / src / lib.ts View on Github external
application.post("/", json(), (request, response, next) => {
    const authorization = request.get("authorization");
    let { connection } = options;

    if (typeof authorization === "string") {
      connection = new Connection({
        accessToken: authorization.substr(7),
        instanceUrl: options.instance,
      });
    }

    if (connection == null) {
      return next(new GraphQLError("Session expired or invalid"));
    }

    runtime(connection, request.body.query).then(
      result => response.json(result),
      error => next(error),
    );
  });
github postlight / glide / src / oauth.ts View on Github external
function createConnection(instance: string, session: Session): Connection {
  const { oauth2, ...tokens } = session;

  return new Connection({
    ...tokens,
    instanceUrl: instance,
    oauth2: new OAuth2(oauth2),
  });
}

jsforce

Salesforce API Library for JavaScript

MIT
Latest version published 11 days ago

Package Health Score

86 / 100
Full package analysis