I am using Nodejs. I am reading a csv file and reading all the Ids and after then i am making a soql query to fetch details as below -

But i dont know why the query is not running.

Is the below written query syntax is wrong as it is not throwing any error.

var stream  = fs.createReadStream('./account.csv')
.pipe(csv({headers: true}))
  var accID = data.ID;
    var query = "SELECT Id,Body,Name,ParentId FROM Attachment where ParentId ='" + accID + "'";
    conn.query(query, function(err, result) {
  • How do you know you're not getting an error or result? You're not logging to the console or anything. – sfdcfox Mar 24 '18 at 16:18
  • if i am debugging, it i coming out from the "var query" line... i am unable to print query... – learnjqueery Mar 24 '18 at 16:24
  • Well, try adding some debug lines: conn.query(query, (err, result) => { console.log(err); console.log(result); }); – sfdcfox Mar 24 '18 at 16:26
  • still the same case...the debugger is coming out ...it is not printing anything.... – learnjqueery Mar 24 '18 at 16:28
  • On question if the variable accID contains two ids 0017F00000UNxkCQAT,0017F00000ZSAxR ... How the soql will be written..I think the soql itself is wrong syntax – learnjqueery Mar 24 '18 at 16:30

You have a variable inside another function, so its scope is limited. Instead, you need the variable outside the scope to collect the values:

var accountIds = [];
var stream  = fs.createReadStream('./account.csv')
.pipe(csv({headers: true}))

Your query is also not correct in this case, as you need to use IN to specify multiple values:

var query = "SELECT Id,Body,Name,ParentId FROM Attachment where ParentId IN ('" + accountIds.join("','")+ "')";

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.