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

Node-Red Debug window showing misleading information #5

Closed dwindibank closed 5 years ago

dwindibank commented 6 years ago

This isn't really an issue with node-red-contrib-salesforce, it's more of an issue with Node-Red's debug window.

When you do a SOQL query the debug window makes it look like the result object is flatter then it actually is. The object returned by the nforce library has get and set methods and it's toJSON function flattens it out.

In the screen shot bellow I created a hello web-service that takes a SalesForce Id and does a SELECT Name FROM Contact WHERE Id = {{msg.req.params.id}} ... based on what you see in the debug window you can end up trying to access properties that aren't really there.

image

I think initially all that is required is some updates to the README.md and the soql.html, so that there is more information about how the result records are actually structured.

Eventually it would be nice to have a option on the Node Config screen that would flatten the object out (rather than returning the nforce object).

Stwissel commented 6 years ago

You are welcome to submit a pull request ;-) ... or describe closer what changes you want to see. Not fully sure how that "flatten" would work - but happy to accomodate

Stwissel commented 6 years ago

@dwindibank I was thinking to add a checkbox: [x] Return JSON only to the SOQL node configuration. This would use the toJSON function in the spirit that the payload passed between nodes should be data only. Default would be checked, so new flows never need to deal with the original JS Object. Would that work for you?

dwindibank commented 6 years ago

Yes, that's exactly what I was thinking ... I was intending to submit a pull request, but I won't have a chance to do so until next week (I'm new to Node-Red development so I suspect it'll take me a couple of hours to do a 10 minute change).

Right now, I have a handful of flows using the SOQL node and in most cases they immediately go into a function node with this code:

//Convert the SalesForce objects from the SOQL query into regular objects
//Then promote the returned records up a level

msg.payload.records = msg.payload.records.map(function (record) {
  return record.toJSON();
});

msg.payload = msg.payload.records;

return msg;

I also bring the records up a level, so that I can then wire it into a Split node.

dwindibank commented 6 years ago

FYI ... I have this ready. I'll copy the changes from the SOQL node to the SOSL node and post a pull request (either tonight or tomorrow). I've added info to the help but that should be reviewed for clarity.

Stwissel commented 6 years ago

@dwindibank - Didn't you want to submit a pull request?

dwindibank commented 6 years ago

Finally got around to the pull request ... thanks for helping with this!