This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다. 현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.
Metadata
ID:apex-code-style/avoid-global
Language: Apex
Severity: Notice
Category: Best Practices
Description
This rule discourages the use of the global access modifier for classes, variables, methods, and inner classes in Apex code. Declaring elements as global exposes them beyond the namespace boundary, making them accessible to all Apex code in any installed package or org, which can lead to unintended dependencies and security concerns.
To comply with this rule, use more restrictive access modifiers such as private, protected, or public whenever possible. For example, instead of global class MyClass, declare it as public class MyClass unless there is a compelling reason to expose it globally. Similarly, avoid defining variables or methods as global; prefer private or public based on the intended visibility.
Non-Compliant Code Examples
global without sharing class GlobalClass {
global String globalAttribute = 'my-attr';
global static void globalStaticMethod() { }
global class GlobalInnerClass { }
}
Compliant Code Examples
private class PrivateClass {
global void exposedMethod() {
// foobar
}
}
class NotGlobalClass {
String notGlobalAttribute = 'my-attr';
static void staticMethod() { }
class InnerClass { }
}
원활한 통합. Datadog Code Security를 경험해 보세요
Datadog Code Security
이 규칙을 사용해 Datadog Code Security로 코드를 분석하세요
규칙 사용 방법
1
2
rulesets:- apex-code-style # Rules to enforce Apex code style.
리포지토리 루트에 위의 내용을 포함하는 static-analysis.datadog.yml을 만듭니다
무료 IDE 플러그인을 사용하거나 CI 파이프라인에 Code Security 검사를 추가합니다