Apex class and trigger names can be up to 40 characters long. That got me thinking…
How long can an Apex identifier (variable) name be?
Apex identifier (variable) names can be up to 255 characters long.
God only knows why anyone would ever want to USE a variable name this long, though!
While researching this, I couldn’t find an “official” answer in the Apex docs. I figured that if it wasn’t 40 characters, then it might be 255. I wanted to know for sure, so I fired up Eclipse to run a quick experiment.
Here’s what I got with a 256 character long identifier. Note the cursor is positioned at column 257, meaning there are 256 characters to the left of it.
Save Error: Identifier name too long
After shortening the name to 255 characters, I could successfully save the class.
So, there you have it. Definitive proof that an Apex identifier name can be up to 255 characters long.
I’m definitely not solving world hunger with this one, but at least if anyone else is ever crazy enough to ask the same question, they’ll find this answer. 🙂