Menu

Custom rule for Querying formula fields should be avoided using apex pmd

Developers
Srividya
2020-10-13
2020-10-23
  • Srividya

    Srividya - 2020-10-13

    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.

     
  • Andreas Dangel

    Andreas Dangel - 2020-10-23

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.