function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ciccic 

string length not compiling?

When compliing the following code:
 
String test = 'test';
Integer len = test.length;
 
I get a compile error on the second line "Initial term of field expression must be an SObject: String".
 
Why can't I use the string length attribute?
 
 
Best Answer chosen by Admin (Salesforce Developers) 
SfdcStevenSfdcSteven
Length is a method, not a property.

String test = 'test';
Integer len = test.length();

Should work.

All Answers

SfdcStevenSfdcSteven
Length is a method, not a property.

String test = 'test';
Integer len = test.length();

Should work.
This was selected as the best answer
ciccic

Thanks.  Sorry.  To used to c# and javascript.   Why is it a method though?????