I am trying to create two second-generation (2GP) packages with the same namespace but running into an issue where one of the packages is not able to access the properties of a class from the other package despite the class being annotated with @namespaceAccessible and throwing an error.
@namespaceAccessible
public with sharing class AuraResult {
public Boolean success = false;
public String message = '';
@namespaceAccessible
public AuraResult() {
}
@namespaceAccessible
public Boolean getSuccess() {
return success;
}
@namespaceAccessible
public void setSuccess(Boolean success) {
this.success = success;
}
@namespaceAccessible
public String getMessage() {
return message;
}
@namespaceAccessible
public void setMessage(String message) {
this.message = message;
}
}
In the example above, I am able to access the @namespaceAccessible methods i.e., getMessage() and setMessage() methods, but unable to access the properties directly:
AuraResult ar = new AuraResult();
String message = ar.getMessage(); // Works
Boolean success = ar.getSuccess(); // Works
message = ar.message; // Throws an error: "Variable is not visible".
success = ar.success; // Throws an error: "Variable is not visible".
Using the getter and setter methods is not ideal as it requires a lot of refactoring in my package. Is this expected behavior or a salesforce bug?