turbot / steampipe-plugin-salesforce

Use SQL to instantly query Salesforce resources. Open source CLI. No DB required.
https://hub.steampipe.io/plugins/turbot/salesforce
Apache License 2.0
9 stars 6 forks source link

Dynamically get Salesforce Object Names and their Field Names #14

Closed d416 closed 1 year ago

d416 commented 1 year ago

Is your feature request related to a problem? Please describe. Unless I'm missing something, it seems that for a Salesforce object to be queryable, the object name must be hard coded into the salesforce.spc config. Can the plugin dynamically query all available Object names and fields names through the connection?

Describe the solution you'd like simpleforce library has a DescribeGlobal() function which returns a list of all objects. https://github.com/simpleforce/simpleforce/blob/acf4ac67ef68eee62febf8e1afac93b55b0e6512/force.go#L336 (I believe field names are fetchable through this function)

Ideally, this plugin should behave more like the CSV plugin, where the number of .csv files, the names of the files, and the columns within each file could widely vary due not only to a SF instance's data model, but also the field-level and object security model. The best way to handle this would be to dynamically get whatever the logged in user is allowed to see. For the plugin description, make only 1 table available, and that is 'Objects' which would return a list of all objects available.

Describe alternatives you've considered The alternative to hard code Object names is cumbersome and not practical, especially for instances which have hundreds of objects (like my company's)

Additional context Access to objects and fields are defined at the user profile level, so having these pre-defined in the plugin may not be an accurate representation of what the logged-in user has access to. For example, in Opportunity there is an out-of-box field called ExpectedRevenue. In my company's instance we've disabled access to this field in lieu of a custom field. But in this plugin, no matter which query I execute on Opportunity (example: select id from opportunity limit 10) I get the error "No such column 'ExpectedRevenue' on entity 'Opportunity'." which is from Salesforce. I've been able to reproduce this in a new developer sandbox.

cbruno10 commented 1 year ago

Hey @d416 , thanks for bringing that function/API to our attention, we hadn't seen that before!

We haven't tested that function yet, but if it's able to retrieve the list of objects in a timely and complete fashion, one way to use it would be to add glob wildcard support to the objects config arg, and then the plugin would match any patterns from objects against the list of retrieved objects.

Would this approach help you get the tables you need?

And for the additional info under Additional context, if you add the Opportunity object to the objects config arg, does that bring in the ExpectedRevenue column (will show up as expected_revenue I believe)? We added some tables as static tables in this plugin to provide the plugin with some initial tables in case users haven't setup the objects config arg yet and also to help generate some Hub documentation with examples, e.g., https://hub.steampipe.io/plugins/turbot/salesforce/tables/salesforce_opportunity. I think these tables can be overriden if included in the objects config arg, but my memory is a bit fuzzy.

d416 commented 1 year ago

Honestly there is no real reason to include any default tables as the access to these tables and fields may be blocked via user-level and/or connected app-level security. Just get the metadata for what the logged-in user has access to and you're golden. If you absolutely need to include tables as examples, just use Account and Contact as nearly every user will have access to these (it is CRM after all). Id and Name fields every user must have access to and these cannot be disabled. So perhaps just include this metadata for example purposes, and then probably just add it as a default to the config file instead of separate .go files

Re: > if you add the Opportunity object to the objects config arg, does that bring in the ExpectedRevenue column (will show up as expected_revenue I believe)?

If a user or the connected app does not have access to the ExpectedRevenue field via Salesforce security settings, no amount of steampipe plugin config will grant them access to that. I hope that helps.

ParthaI commented 1 year ago

While attempting to list the available objects using the DescribeGlobal API before table initialization, I encountered the error message json: cannot unmarshal array into Go value of type simpleforce.SObjectMeta). This error is preventing me from successfully making the API call.

To address this issue, I have raised an issue on the SDK team's GitHub repository. we can track the progress of the issue at: GitHub Issue #61.

Thank you for your understanding.

bigdatasourav commented 1 year ago

Hello @d416, we are closing the issues due to the API issue mentioned earlier. Once we have any updates, we will get back to it. If you have anything to share or talk about, please feel free to reopen the issue whenever you get a chance. I appreciate your understanding.