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

Protected method in abstract class gives error

I get the "Method is not visible" error when a subclass extends an abstract class and implements an abstract method that is protected.  That method is called from the abstract class.  This is common implementation in other languages, but am getting an error when attempting this in Apex.  Only work around seems to be to make the method in the subclass that implements it to be public, even if it is only called from within the class.


Any ideas?


public abstract class SalesRecord_SupportCalc_Base { public SalesRecord_SupportCalc_Base(List<Id> salesRecordIds){ } protected abstract void RetrieveSalesRecords (); public void CalculateSupport(){ RetrieveSalesRecords(); } } public class SalesRecord_SupportCalc_Quote extends SalesRecord_SupportCalc_Base { public SalesRecord_SupportCalc_Quote(List<Id> salesRecordIds){ super(salesRecordIds); } protected override void RetrieveSalesRecords (){ } }


Just a friendly bump to see if anyone has any ideas why you cannot call a protected method from a public method within an abstract class.

Hi Malathan,


I faced the same problem - See:


and haven't gotten any replies either :(


You can make your overridden method public or make your classes inner classes (which hopefully solves your immediate problem). AFAICT, protected works like a Java package private for inner classes and not as expected for outer classes.