Usage of parameter/variable not found when it's in a SOQL String.

Issue #1662 resolved
Justin Julicher created an issue

String region is highlighted as not used but it is used in the query string on the last line.

Maybe there should be some validation that it must be preceeded by an ‘equals/not equals’, ‘in’ or other operator.

Comments (4)

  1. Scott Wells repo owner

    Justin, this is due to a fix that I made in the most recent release to eliminate a reference being added when it shouldn't. Now I analyze the string in which a candidate usage is found to determine whether it's part of a dynamic query or not. There are two situations in which I decide that it is: 1) that exact string literal begins with SELECT or FIND; 2) that string literal is in a string concatenation expression that itself begins with one of those two keywords. In the example you've provided, it will no longer be found. I'll consider extending that heuristic, perhaps to look for other keywords such as WHERE, AND, OR, LIMIT, OFFSET, etc., which should address the majority of cases while still minimizing the chance of an incorrect reference addition.

  2. Justin Julicher reporter

    That solution sounds good. Even if there is a small chance of a false positive it’s better than the false negative (that currently happens) as I feel a false negative gives the impression that the parameter/variable could be removed when in fact it can not/shouldn’t be.

  3. Scott Wells repo owner

    Yep. And I've already committed the change for inclusion in the next build that will likely go out Friday morning.

  4. Log in to comment