0

I am using the below code to establish a connection with Salesforce connected app -

const express = require('express'); //Adding Express
const http = require('http'); //Adding http
const jsforce = require('jsforce'); //Adding JsForce

const app = express();
app.set('port', process.env.PORT || 8080);
let accessToken;
app.get('/', function (req, res) {
    var conn = new jsforce.Connection({
        // you can change loginUrl to connect to sandbox or prerelease env.
        oauth2: {
            loginUrl: 'https://login.salesforce.com/services/oauth2/token',
            clientId: 'clientId',
            clientSecret: 'clientSecret',
            redirectUri: 'https://login.salesforce.com/services/oauth/success'
        }

    });
    var username = 'username';
    var password = 'password+security token';
    conn.login(username, password, function (err, userInfo) {
        if (err) { return console.error(err); }
        console.log(conn.accessToken);
        console.log(conn.instanceUrl);
        console.log("User ID: " + userInfo.id);
        console.log("Org ID: " + userInfo.organizationId);
        res.send('heySalesforce : JSForce Connect Succeeded!');
    });
});
http.createServer(app).listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});

Here is the snip of the connected app in Salesforce - enter image description here I dont get anything printed out of the app.get function to the console. Could someone point what careless mistake I am causing here.

4
  • Welcome to SFSE! Please take a moment to read How to Ask and take the tour. Including a Minimal, Complete and Reproducible example would be helpful. What you have is one side of the story - the client side - thus making your example incomplete and not reproducible.
    – identigral
    Nov 20 at 22:34
  • 1
    The other side is a connected app in Salesforce. I have added the snip to the post.
    – sumchans
    Nov 20 at 22:43
  • 1
    JSforce doc (at least the first code sample on jsforce.github.io/document/#connection) is wrong with respect to Resource Owner Password Credentials flow. Not only the doc is wrong, the flow has been outlawed by the industry due to (severe) security issues and SF defaults turn off this flow for newer orgs. Reimplement the connection based on Authorization Code (aka jsforce.OAuth2) flow.
    – identigral
    Nov 20 at 23:27
  • 1
    @identigral Yes, I saw that and was able to fix it.
    – sumchans
    Nov 20 at 23:32

0

You must log in to answer this question.

Browse other questions tagged .