Stwissel / node-red-contrib-salesforce

A set of Node-RED nodes to interact with Salesforce and Force.com
MIT License
10 stars 17 forks source link

bug in how soql queries return in node-red #19

Closed javaknight closed 5 years ago

javaknight commented 6 years ago

When using the soql node, the initial records object that comes back is not transformed in time for node-red to use it.

Execute any reasonable soql query, and ask it to return all result records (although, this shouldnt matter). in my case, i'm looking for an "id" property. assuming you've got records to return...

now, attach a Javascript node at the output of your node:

node.warn(msg.payload.records[0].id); // emits undefined node.warn(msg.payload.records[0].toJSON().id); // emits the data I'm looking for. node.warn(Object.keys(msg.payload.records[0])); // as you can see this shows the issue - this is the object from the nforce wrapper and hasn't been transformed in time yet to be accessed properly - this is the bug I am pointing out. node.warn(JSON.stringify(Object.keys(msg.payload.records[0]))); // just another view of above

You can also clone msg.payload.records[0] using the stringify/parse method, which gets you the data you need, because it's synchronous

so in short, I believe the bug is that the soql method isn't blocking properly, and thus the user cannot access the data as they would expect.

Stwissel commented 6 years ago

There's a quirk in the current implementation. The API call currently does NOT return a JSON object but a JavaScript object. That's why records[0].toJSON().id returns you the value you are looking for. records[0] is a JavaScript object. We probably implement a switch to return JSON only which is the more NodeRED style. Just need to check if we break existing apps

Stwissel commented 6 years ago

Actually the same observation as #5

Stwissel commented 5 years ago

Starting 0.6 only JSON gets returned