Type or member declared global
ID |
apex.maintainability.avoid_global |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Api Design |
Language |
Apex |
Description
Reports a class, interface or method declared global rather than public. A member of a class that is itself global is not reported separately - the type carries the finding.
Rationale
global publishes the member outside its namespace, and in a managed package that is permanent: once a version ships, a global method cannot be removed and its signature cannot change, because a subscriber org may be calling it. Every global therefore freezes a design decision forever, and most of them are written by habit rather than because an external caller exists.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Type or member declared global
global class PackageEntry {
global static void run(Id recordId) {
System.debug(recordId);
}
public static void helper(Id recordId) {
System.debug(recordId);
}
}
Remediation
Use public unless the member is genuinely part of the package’s external API - a webservice entry point, an interface a subscriber implements, or a method Flow or an external system calls. Where it is, keep the surface as small as possible: publish one entry point rather than a whole class.