public interface Constants{
    String TEST = 'test';


I am getting below error -

Error: Compile Error: expecting a left parentheses, found '=' at line 2 column 16   

Can someone explain why am i getting this error?

  • 3
    You may have thought you could do that because Java supports constants in interfaces, but Apex does not. Depending on your use case you might want to consider Custom Labels or Custom Settings – Peter Knolle Dec 8 '12 at 12:42

Interfaces should have only method declarations. If you think you need member variables within this new type you're creating - you most likely want to make a class that you'll extend later on. Probably even an abstract class?

public abstract class Constants{
    String TEST = 'test';

I fail to understand how someone might think he later needs to write class MyConstants extends Constants (or implements if you'd follow the interface path)...

Please don't name your classes or variables Test, this can lead to some interesting compilation errors ;) And last but not least - this should probably be a public static final String testString...


You can't declare a constant in an interface, or for that matter implement any code other than method signatures (which you must then implement in a Class). An interface is a fairly generic term across programming languages. You can read about it in general here:


Or, specifically in Apex here:


However, it looks like you might want an enum (or a class) though for what you're doing, you can read up on that here:


Or if you simply want it as a class:

    public class Constants {
        public static final TEST = 'test';

So you can access it elsewhere as:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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