I'am trying to call a apex class method from another apex class which is a part of unlocked org dependant package.
Below is the class in package (Class is present as a part of installed package):
global with sharing class AccountUtil {
global AccountUtil() {
}
global static List<Account> getFewAccounts() {
return AccountUtil2.getSomeAccounts();
}
}
Class which is outside of unlocked package which does not have any namespace :
global class AccountUtil2 {
global AccountUtil2() {
}
global static List<Account> getSomeAccounts() {
return [SELECT Name FROM Account LIMIT 3];
}
global List<Account> getAccounts() {
return [SELECT Name FROM Account LIMIT 3];
}
}
When I execute namespace.AccountUtil.getFewAccounts();
in Anonymous window , it shows below error :
Dependent class is invalid and needs recompilation: Class namespace.AccountUtil : Variable does not exist: AccountUtil2
Is there a restriction which says that apex classes outside of unlocked, org dependant classes cannot be referenced inside the package?
Use case - We are in the process of converting large codebase into unlocked, org dependant packages gradually. Hence, this becomes important to create namespaces in modularised way.
global
?AccountUtil2
global since it was not visible inside the package class. Package class can be public. The package class gets saved with reference toAccountUtil2
but fails at runtime.global
is required when working across the namespace boundary, though only in the direction of dependency. If the packaged class must be directly accessible outside the package, it must beglobal
. If the package must directly access a class outside the package, it must beglobal
. I cannot help specifically with the org dependent nature of your package, but I can say that when using unlocked packages, I found providing them a namespace caused me grief, so I ended up not using a namespace.@NamespaceAccessible
annotation to allow communication across their boundaries with each other.