0

Hi Im trying to connect Salesforce with microsoft bot framework for creating a skype Bot. I use Express node js and node-salesforce for connecting Salesforce.

I have written Salesforce functions in separate file(Salesforce js) and Bot Functions in a separate file(myBot js) which is the server file. The query function in Salesforce js getting called successfully but its not returning the result back to the calling function.Here is the code, please someone help

Mybot Js function

var intents = new builder.IntentDialog();
intents.matches(/^QueryAcc/i, [
   function (session) {
      Salesforce.QueryAcc();
   },
   function (session, results) {
      console.log('the response--'+results.response);
   }
]);

Salesforce Js Function

function QueryAcc(){
var records = [];
conn.query("SELECT Id, Name FROM Account limit 1", function(err, result) {
  if (err) { 
    return console.error(err); 
  }else{
    console.log("fetched : " + result.records);
   for (var i=0; i<result.records.length; i++) {
     var record = result.records[i];
   }
   console.log("First Name: " + result.records[0].Name);
   return record;
  }
});
}

1 Answer 1

1
function QueryAcc(callback){

    conn.query("SELECT Id, Name FROM Account limit 1", function(err, result) {
        if (err) {
            console.error(err);
        }
        else{
            var records = [];
            console.log("fetched : " + result.records);
            for (var i=0; i<result.records.length; i++) {
                var record = result.records[i];
                records.push(record);
            }
            console.log("First Name: " + result.records[0].Name);
            callback(records);
        }
    });
}


var intents = new builder.IntentDialog();
intents.matches(/^QueryAcc/i, [
    function (session) {
        Salesforce.QueryAcc(function(results){
            console.log('the response--'+results.response);
        });
    }
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.