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
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?

share|improve this question
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
up vote 7 down vote accepted

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

share|improve this answer

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:

share|improve this answer

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.