1

Let's say I'm overriding the default retrieve operation for a Visualforce Remote Object so I can use custom SOQL to execute a query and add related (nested) data. In order to create a query, it'd be ideal to re-use Salesforce's parser that they use to take the Remote Objects Query Criteria containing where, offset, and limit, to validate these and turn them into valid SOQL snippets I can use in my query.

Surely, this happens internally already, but is any such facility exposed to me, the developer?

For example, let's say we use JavaScript remoting / @RemoteAction to override retrieve like in this example https://salesforce.stackexchange.com/a/45193/7215. However, instead of calling RemoteObjectController.retrieve, I want to call Database.query('SELECT Id, Name, (SELECT Name FROM Orders__r) FROM Account' + criteria to get my results using dynamic SOQL.

My goal is to define the criteria variable in this example. The resulting string might look like WHERE Id = 'someSalesforceId' LIMIT 1 OFFSET 2 depending on the actual criteria, but this would ideally be validated against the object to make sure the fields were valid, and that SOQL injection didn't occur. I could build that myself, but Salesforce is obviously already doing this internally, so I wonder if we can reuse that logic.

5
  • 1
    Can you add some code to demonstrate what you are doing so far?
    – Adrian Larson
    Jul 28, 2017 at 14:30
  • Does the override actually let you see the criteria to begin with? I'm not sure you can do that.
    – sfdcfox
    Jul 28, 2017 at 15:12
  • I've updated the question with small examples of code. The signature for the override would be static Map<String, Object> retrieveOverride(String type, List<String> fields, Map<String, Object> criteria), so you could parse the criteria in this example, using the syntax in the first article I linked to.
    – jon_wu
    Jul 28, 2017 at 15:26
  • hey @jon_wu any luck? I am trying something similar here: salesforce.stackexchange.com/questions/192457/… Sep 17, 2017 at 3:51
  • @SFDC_peter for now, I'm going with a simpler, less-performant solution. I'm going to write some code on the frontend to recursively fetch relationships, one at a time. Unfortunately, this will be one roundtrip for each traversal, but it will keep things simple for now. Later, I think we'll just add hard-coded queries with remoting, but it will be one-off for now. There's still a bit of thinking even on the backend when getting nested relationships. At least my frontend implementation will have a cache of all related IDs so it'll safe some fetches if there are multiple references to something.
    – jon_wu
    Sep 20, 2017 at 15:32

0

You must log in to answer this question.

Browse other questions tagged .