Update documentation
This commit is contained in:
@ -16,7 +16,6 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [ApexUnitTestClassShouldHaveAsserts](pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts): Apex unit tests should include at least one assertion. This makes the tests more robust, and usi...
|
||||
* [ApexUnitTestShouldNotUseSeeAllDataTrue](pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue): Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database...
|
||||
* [AvoidGlobalModifier](pmd_rules_apex_bestpractices.html#avoidglobalmodifier): Global classes should be avoided (especially in managed packages) as they can never be deleted or...
|
||||
* [AvoidHardcodingId](pmd_rules_apex_bestpractices.html#avoidhardcodingid): When deploying Apex code between sandbox and production environments, or installing Force.com App...
|
||||
* [AvoidLogicInTrigger](pmd_rules_apex_bestpractices.html#avoidlogicintrigger): As triggers do not allow methods like regular classes they are less flexible and suited to apply ...
|
||||
|
||||
## Codestyle
|
||||
@ -42,6 +41,7 @@ List of rulesets and rules contained in each ruleset.
|
||||
|
||||
## Error Prone
|
||||
* [AvoidDirectAccessTriggerMap](pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap): Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be ...
|
||||
* [AvoidHardcodingId](pmd_rules_apex_errorprone.html#avoidhardcodingid): When deploying Apex code between sandbox and production environments, or installing Force.com App...
|
||||
* [EmptyCatchBlock](pmd_rules_apex_errorprone.html#emptycatchblock): Empty Catch Block finds instances where an exception is caught, but nothing is done. In most cir...
|
||||
* [EmptyIfStmt](pmd_rules_apex_errorprone.html#emptyifstmt): Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
||||
* [EmptyStatementBlock](pmd_rules_apex_errorprone.html#emptystatementblock): Empty block statements serve no purpose and should be removed.
|
||||
|
@ -5,7 +5,7 @@ permalink: pmd_rules_apex_bestpractices.html
|
||||
folder: pmd/rules/apex
|
||||
sidebaractiveurl: /pmd_rules_apex.html
|
||||
editmepath: ../pmd-apex/src/main/resources/category/apex/bestpractices.xml
|
||||
keywords: Best Practices, ApexUnitTestClassShouldHaveAsserts, ApexUnitTestShouldNotUseSeeAllDataTrue, AvoidGlobalModifier, AvoidHardcodingId, AvoidLogicInTrigger
|
||||
keywords: Best Practices, ApexUnitTestClassShouldHaveAsserts, ApexUnitTestShouldNotUseSeeAllDataTrue, AvoidGlobalModifier, AvoidLogicInTrigger
|
||||
---
|
||||
## ApexUnitTestClassShouldHaveAsserts
|
||||
|
||||
@ -116,46 +116,6 @@ global class Unchangeable {
|
||||
<rule ref="rulesets/apex/bestpractices.xml/AvoidGlobalModifier" />
|
||||
```
|
||||
|
||||
## AvoidHardcodingId
|
||||
|
||||
**Since:** PMD 6.0.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
When deploying Apex code between sandbox and production environments, or installing Force.com AppExchange packages,
|
||||
it is essential to avoid hardcoding IDs in the Apex code. By doing so, if the record IDs change between environments,
|
||||
the logic can dynamically identify the proper data to operate against and not fail.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.apex.rule.bestpractices.AvoidHardcodingIdRule](https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidHardcodingIdRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public without sharing class Foo {
|
||||
void foo() {
|
||||
//Error - hardcoded the record type id
|
||||
if(a.RecordTypeId == '012500000009WAr'){
|
||||
//do some logic here.....
|
||||
} else if(a.RecordTypeId == '0123000000095Km'){
|
||||
//do some logic here for a different record type...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|cc_categories|[Style]|Code Climate Categories|
|
||||
|cc_remediation_points_multiplier|1|Code Climate Remediation Points multiplier|
|
||||
|cc_block_highlighting|false|Code Climate Block Highlighting|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/apex/bestpractices.xml/AvoidHardcodingId" />
|
||||
```
|
||||
|
||||
## AvoidLogicInTrigger
|
||||
|
||||
**Since:** PMD 5.5.0
|
||||
|
@ -5,7 +5,7 @@ permalink: pmd_rules_apex_errorprone.html
|
||||
folder: pmd/rules/apex
|
||||
sidebaractiveurl: /pmd_rules_apex.html
|
||||
editmepath: ../pmd-apex/src/main/resources/category/apex/errorprone.xml
|
||||
keywords: Error Prone, AvoidDirectAccessTriggerMap, EmptyCatchBlock, EmptyIfStmt, EmptyStatementBlock, EmptyTryOrFinallyBlock, EmptyWhileStmt, MethodWithSameNameAsEnclosingClass
|
||||
keywords: Error Prone, AvoidDirectAccessTriggerMap, AvoidHardcodingId, EmptyCatchBlock, EmptyIfStmt, EmptyStatementBlock, EmptyTryOrFinallyBlock, EmptyWhileStmt, MethodWithSameNameAsEnclosingClass
|
||||
---
|
||||
## AvoidDirectAccessTriggerMap
|
||||
|
||||
@ -44,6 +44,46 @@ trigger AccountTrigger on Account (before insert, before update) {
|
||||
<rule ref="rulesets/apex/errorprone.xml/AvoidDirectAccessTriggerMap" />
|
||||
```
|
||||
|
||||
## AvoidHardcodingId
|
||||
|
||||
**Since:** PMD 6.0.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
When deploying Apex code between sandbox and production environments, or installing Force.com AppExchange packages,
|
||||
it is essential to avoid hardcoding IDs in the Apex code. By doing so, if the record IDs change between environments,
|
||||
the logic can dynamically identify the proper data to operate against and not fail.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.apex.rule.errorprone.AvoidHardcodingIdRule](https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidHardcodingIdRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public without sharing class Foo {
|
||||
void foo() {
|
||||
//Error - hardcoded the record type id
|
||||
if(a.RecordTypeId == '012500000009WAr'){
|
||||
//do some logic here.....
|
||||
} else if(a.RecordTypeId == '0123000000095Km'){
|
||||
//do some logic here for a different record type...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|cc_categories|[Style]|Code Climate Categories|
|
||||
|cc_remediation_points_multiplier|1|Code Climate Remediation Points multiplier|
|
||||
|cc_block_highlighting|false|Code Climate Block Highlighting|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/apex/errorprone.xml/AvoidHardcodingId" />
|
||||
```
|
||||
|
||||
## EmptyCatchBlock
|
||||
|
||||
**Since:** PMD 6.0.0
|
||||
|
Reference in New Issue
Block a user