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?

1 Answer 1


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 at 256 characters

Save Error: Identifier name too long

After shortening the name to 255 characters, I could successfully save the class.

Success: A 255 character long identifier works fine

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. :-)

  • 20
    I learned that the hard way when I tried to use thisVariableIsUsedToStoreTheTotalAmountOfWidgetAsPlusWidgetBsDividedByTheSquareRootOfAToTheSecondPowerAndThenUsingADifferentLongDivisionCalculationToAdjustTheCompleteNumberThenUsingThatValueToHandleTheRestOfTheCalculationDividedByItselfSoTheAnswerShouldBe1 and had to switch it to theVariableIsUsedToStoreTheTotalAmountOfWidgetAsPlusWidgetBsDividedByTheSquareRootOfAToTheSecondPowerAndThenUsingADifferentLongDivisionCalculationToAdjustTheCompleteNumberThenUsingThatValueToHandleTheRestOfTheCalculationDividedByItselfSoTheAnswerShouldBe1 Apr 9, 2015 at 1:49
  • LOL! Best comment ever! :-) Apr 9, 2015 at 3:39
  • 2
    FYI You never did accept your own answer.
    – Adrian Larson
    Jun 22, 2017 at 15:37
  • 1
    @AdrianLarson - Thanks for noticing that and letting me know! Done! Jun 25, 2017 at 17:40
  • 1
    @BradUllery wat a comment!! ... rofl Jan 11, 2019 at 9:14

You must log in to answer this question.

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