-1

Is there way I can do some sort of query in my org to see if any of our apex classes uses the DescribeSObjectResult class? if so how can I achieve that?

Thanks!

0
3

You can query apex classes but cannot query if it contains 'DescribeSObjectResult' as its a text area.

Other way would be to use SOQL + Apex for it.

for(List<ApexClass> apexClasses : [SELECT Id, Name , Body FROM ApexClass]){
    for(ApexClass apexClass : apexClasses){
        if(apexClass.Body.contains('DescribeSObjectResult')){
            System.debug(apexClass.Name);
        }
    }
}
2
  • I'd prefer to use SOSL for searches like this, IMO. Also, contains is case-sensitive, perhaps containsIgnoreCase would be a better solution.
    – sfdcfox
    Jan 11 at 3:12
  • @sfdcfox agreed. Though if class is directly used via chaining none of the methods would work. If we can use symbol table to determine dependencies that would be ideal. Illuminated Cloud does it Jan 11 at 9:22
4

No, this is not something that SOQL or SOSL is capable of.

This is generally something that you'd use your IDE (Integrated Development Environment, such as VisualStudio Code) for, which should have a general "search for this string in all files" feature.

After a little more testing, it does appear that SOSL is capable of this

FIND "describeSObjectResult" IN ALL FIELDS RETURNING ApexClass(Name)

The "IN ALL FIELDS" bit is optional (as ALL FIELDS is the default). If you have your codebase in salesforcedx projects, I still believe that using the features of an IDE is going to be an overall easier approach.

2
  • 1
    Actually SOSL is capable of searching ApexClass, I'm pretty sure I've seen it used here and there.
    – Adrian Larson
    Jan 10 at 16:02
  • @AdrianLarson ah, looks like my quick and dirty test was a little too quick and a little too dirty.
    – Derek F
    Jan 10 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.