I need to come up with a SOQL Query for the code used limit, which is apporaching it's maximum. I want to identify the Classes that are using the most characters. What should I query to identify the largest Classes and get the right number of characters in them?

enter image description here

1 Answer 1


Not quite sure if I understand what you're asking for, but I'll give it a shot.

I believe that you're looking for the apexclass object, which can be queried via SOQL.

It ends up being a simple query

[SELECT Id, Name, LengthWithoutComments FROM ApexClass ORDER BY LengthWithoutComments DESC]

The above will give you a list of Apex Classes, as well as their size, from the largest to the smallest.

Note that triggers also contribute to the characters of code that you're allowed to have. The query for those is exactly the same, you just need to replace 'ApexClass' with 'ApexTrigger' (link to ApexTrigger docs)

  • 1
    I had this come up on twitter today and I ended up with a similar solution. I added an additional where LengthWithoutComments > 0 clause to exclude managed classes contributing a lot of -1 values. Commented May 12, 2022 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .