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;}


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

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.

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.

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.

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.