Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The limit on the amount of characters you can have in Apex is 3,000,000. I understand that comments and test classes do not count towards this limit. Another developer just asked me if the space character counts and I could not answer with certainty. I hope that someone out there can tell me that they do not count against the character limit.

share|improve this question
They won't if they're inside comments though. – sfdcfox May 29 '14 at 15:33
This is a very good point! – Simon Lawrence May 29 '14 at 15:38
up vote 16 down vote accepted

A quick test would suggest that they do...

Here is a simple class in my DE

simple class

and the code usage


If I add loads of characters, the usage goes up..

duff characters

usage 2

when I removed them, it went back down, now I added loads of white space, and the usage climbed again:

white space

usage 3

And this is chaining lots of spaces together, so I would say that lots of individual spaces in real code will behave the same way..!

It even counts spaces at the end of a line, as you can see here:

end of line

usage 5

It does also count the spaces at the start of a line (the indentation)


It does not appear to count spaces in lines containing nothing but spaces though!

share|improve this answer
Did you test extra spaces at the end of a line? – sfdcfox May 29 '14 at 15:32
I did not... but just for you @sfdcfox please see the edit ;) – Simon Lawrence May 29 '14 at 15:33
and an interesting revelation in the last line of the answer regarding lines containing nothing BUT spaces.. – Simon Lawrence May 29 '14 at 15:37
Thank you for taking the time to figure that out, Simon. We try to keep our code formatted for readability but I guess we'll just need to keep it ugly as we get close to our character limit. – aspire4more May 30 '14 at 17:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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