Binding variables in SOQL editor

Issue #188 new
Jacek Nakonieczny created an issue

If i try to use static variable in SOQL editor i got error "Bind variables only allowed in Apex code".

Classes and variables are properly linked to it's source so why not evaluate if necessary (binding operator) if needed?

class Consts {
    public static final String CUSTOM_OBJECT_STATUS_OK = 'OK';

And in SOQL Editor

FROM Custom_Object__c
WHERE Object_Status__c = :Consts.CUSTOM_OBJECT_STATUS_OK

Comments (3)

  1. Scott Wells repo owner

    Jacek, I'm assuming you mean the SOQL Query tool window by SOQL editor and not an inline SOQL query inside of Apex source? Assuming so, that's a limitation of Salesforce itself. When you run an ad hoc SOQL query, you can't use bind variables because there's no runtime Apex context when the query is executed. I'm reusing the same parser/editor/etc. for the SOQL Query tool to provide completion and such which is why it may seem like you can do that, but Salesforce actually won't let you.

    Please let me know if I'm misunderstanding the issue you're seeing.

  2. Jacek Nakonieczny reporter

    Yes. I had SOQL Query tool in mind.

    Folks from Real Force Explorer tool managed to develop similar functionality where you need to specify bound values by hand. This would be nice entry point of this feature. Given that resolving simple static data structures like ,in example, Strings, Integers or Lists can be second step.

    Of course this can become really tricky, but not impossible, if we take into account variables that depend on runtime.

  3. Scott Wells repo owner

    Ah, I see. For static bind variables, this would be pretty simple, but as you noted, there's not really a great way to do this with those that depend on runtime information. The best recommendation I might have would be to use the Anonymous Apex tool window instead and System.debug() the query results. Theoretically I could detect those and render them as a table, but I'd want to see how broadly applicable this enhancement might be before prioritizing it over other features on the backlog.

    I'm curious as to the advantages of this over just setting the static bind variable values directly in the query. It seems like an unnecessary level of indirection. Not arguing the value of it...just trying to understand it better.

  4. Log in to comment