• Divy Muni
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I am attempting to get a a record id to use in my automation tests however when I attempt to execute the below code the returned value is a promise.  Within the promise I can see the id however I cannot seem to access it.  Am I going about this wrong?

    var jsforce = require('jsforce');

    function querySF() {
        var conn = new jsforce.Connection({
            // you can change loginUrl to connect to sandbox or prerelease env.
            loginUrl: 'https://www.salesforce.com'
        });
    return conn.login('some username', 'some password')
        .then(function(userInfo) { 
            // Now you can get the access token and instance URL information.
            // Save them to establish connection next time.
            console.log(conn.accessToken);
            console.log(conn.instanceUrl);
            // logged in user property
            console.log("User ID: " + userInfo.id);
            console.log("Org ID: " + userInfo.organizationId);
            // ...

            return conn.query("SELECT Id FROM anObject__c Where name = 'the name'")
        })
        .then(function(result){
              console.log("total : " + result.totalSize);
              console.log("fetched : " + result.records.length);
              // is returning the id
              console.log(result.records[0].Id);
              // the class that calls the methods saves it to a variable, the variable is undefined
              return result.records[0].Id;
        })
        .catch(function(err){
            console.error(err);
        });
    }

The way I am calling the method is from a different class.  The class the above method is in is called 'helper'.  from my TC class I am calling `Helper.querySF();(returns the promise)`
I have also tried 

    Helper.querySF(Id).then(function(Id){
    //do what i need to do with the id
    });