1

I am attempting to modify this code:

https://github.com/jeffdonthemic/node-streaming-socketio/blob/master/app.js

So that as well as setting up the streaming, on startup it also performs a query to retrieve some records which are displayed to the user. I am attempting to place code like so:

var q = 'SELECT Id, Name, CreatedDate, BillingCity FROM Account';

sfdc.query({ query: q }, function(err, resp){

  if(!err && resp.records) {

    // do something with record, display to client
  }
});

After the connection and ouath have been set up, however, I am unsure where to place that code in the lifecycle of the main application (app.js). Also, I am unsure how to pass this record once I have it so that it can be displayed on the client side. I keep getting this error when placing this code at various places in app.js:

TypeError: Cannot read property 'instance_url' of undefined
  • I think the problem is the code is over 2 years old and there have been alot of changes to nforce. I'm upgrading the code now and will push it as soon as i can. – Jeff Douglas Oct 18 '14 at 14:57
  • OK.. I've updated the code in this repo so you may want pull it again. Much less code now with the update to nforce. Also, I'm not sure if you actually need to use the streaming api or are just trying to CRUD records from salesforce. You may also want to check out this repo for some basic code: github.com/jeffdonthemic/node-nforce-demo. – Jeff Douglas Oct 19 '14 at 14:27
  • @JeffDouglas awesome, thanks! and actually, I need my app to do both :) i'll check out the other repo – logeyg Oct 20 '14 at 1:56
  • @JeffDouglas I'm still getting the same error, I'm placing a query after where you commented ' // add any logic to perform after login '. Is that the correct place? I'm thinking my callback url might not be correct in the remote app, should it still be set to localhost? – logeyg Oct 20 '14 at 14:32
  • Yes! Your callback in Salesforce should be something like localhost:3000 or whatever port you are using. Also, make sure your password contains your security token in the app. – Jeff Douglas Oct 20 '14 at 14:53
2

One possible cause would be that you are querying before the oauth callback is over.

Make sure you query after successful callback of authenticate()

org.authenticate(username:'',password:'' ,function(err,resp){

if(!err) //query here })

//query here will give the error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.