I have a virtual class with non virtual and virtual methods:
public virtual class ComponentVisibility {
protected Id currentUserId = null;
protected String currentUserRole = '';
protected String currentProfileName = '';
protected User user = null;
protected void setProfileName() {
currentProfileName = [
SELECT Name
FROM profile
WHERE id =: userInfo.getProfileId()
].Name;
}
protected virtual void setRecordOwnerId() {}
.
.
.
.
}
I have a child class:
public class LeadComponentVisibility extends ComponentVisibility {
private Id leadId;
private Id leadOwnerId;
private String leadOwnerRole;
public override void setRecordOwnerId() {
leadOwnerId = [
SELECT id, OwnerId
FROM Lead
WHERE id =: this.leadId
].OwnerId;
}
}
If I instantiate LeadComponentVisibility lcv = new LeadComponentVisibility();
in another class LeadComponentVisibilityFacade
and call lcv.setRecordOwnerId();
, works fine. But if call lcv.setProfileName()
, I get Method is not visible: void ComponentVisibility.setProfileName()
. If I make setProfileName()
Public
it works. Why? Isn't setProfileName()
inherited?
If I do ComponentVisibility leadComponentVisibility = new LeadComponentVisibility();
instead of LeadComponentVisibility lcv = new LeadComponentVisibility();
and call leadComponentVisibility.setRecordOwnerId();
I get the same Method is not visible error. Why?
I did read the doc which says:
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.
So what am I doing wrong.