Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm trying to create a subclass of BaseClass (SecondClass). SecondClass is extending BaseClass.

BaseClass is a abstract class, which has a member variable sList.

Since I am extending BaseClass in my SecondClass, I guess we can use sList here in SecondClass.

But when I am saving the SecondClass, I am gating

Saving Error : member variable not visible for assignment

Any Idea?

public with sharing class SecondClass extends BaseClass {

   private void init() {

         //this.sList = new SelectorList();
   }


}



public abstract class BaseClass {

   public SelectorList sList {get; private set;}

}
share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

The problem is that you are using the private access modifier on your setter in your base class.

private
This is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.

You need to use protected or public on your setter to be able to call it in a subclass.

protected
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables. Note that it is strictly more permissive than the default (private) setting, just like Java.

public
This means the method or variable can be used by any Apex in this application or namespace.

Documentation on Access Modifiers can be found here.

share|improve this answer
add comment

Your Answer

 
discard

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.