function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul SharmaRahul Sharma 

Programatically reading apex classes

Hello Board,


I am eager to know the best way by which we can parse Apex Class, for checking how many SOQL queries are in for loop.

- One of many ways is to fetch Class in text from ApexClass object then using string manipulation identify queries inside for loops. But queries inside methods or another class method would be very dificult to identify.


Please shed some lights on on better way to parse the Apex Class. Thanks all for your time.


Hi Rahul,

Could you elaborate a bit more on what you want to do that the Security Scanner doesn't already do?


I don't remember if the security scanner detects queries inside a method called from inside a loop, but are you looking for anything else besides that?


I agree with you that it would be difficult to do this manually, you would have to identify method calls besides just identifying the queries.


We played with the idea of doing something along those lines some time ago but we ended deciding that it was too much effort and that a combination of the Security Scanner plus Peer Code Reviews was the way to go.




Rahul SharmaRahul Sharma

MarcoTimba, Thanks for your reply.


I agree that Security scanner works very well, But It still has risk of exposing our code to a 3rd party application.

It would be great if we can built such application in native salesforce so as to avoid such risks.