Custom rule for Querying formula fields should be avoided using apex pmd
A source code analyzer
Brought to you by:
adangel,
juansotuyo
Hi,
In Apex Iam trying to check if the filtering of query is done on formula fields. I am trying to write a custom rule to avoid the below scenario
SELECT Id, Name FROM Account WHERE FormulaField__c = '10' -->Should not be allowed.
Is there a way to fetch the fields of SOQL queries using ASTSoqlExpression or other pmd- apex classes that deal with SOQL.
You can get the query as a string via
@CanonicalQuery
(getCanonicalQuery()
), but I'm not aware of any further structuring. Altough the parser definitely parses the SOQL query as well, but we don't seem to have access to the parsed query.