Recommendations to fixing issues in Apex code

Posted by Abhishek on July 20, 2020

Salesforce Best Practices

Best Practices

Apex Unit Test Class Should Have Asserts
Apex Unit Test Should Not Use SeeAllData=True
Avoid Logic In Trigger
Unused Local Variable
Avoid Global Modifier
Apex Assertions Should Include Message
Debugs Should Use Logging Level
Apex Unit Test Method Should Have IsTest Annotation

Code Smell

Avoid Hardcoding Id
Method With Same Name As Enclosing Class
Avoid Direct Access Trigger Map
Empty If Statement
Empty Statement Block
Empty Try Or Finally Block

Code Styling

If Statements Must Use Braces
If-Else Statements Must Use Braces
Field Declarations Should Be At Start
Method Naming Conventions
Local Variable Naming Conventions
Formal Parameter Naming Conventions
Property Naming Conventions
Field Naming Conventions
Class Naming Conventions

Design

Cyclomatic Complexity, Standard Cyclomatic Complexity, Cognitive Complexity
Range Meaning
5 Change absolutely required. Behavior is critically broken/buggy
4 Change highly recommended. Behavior is quite likely to be broken/buggy
3 Change recommended. Behavior is confusing, perhaps buggy, and/or against standards/best practices
2 Change optional. Behavior is not likely to be buggy, but more just flies in the face of standards/style/good taste
1 Change highly-optional. Nice to have
Avoid Deeply Nested If Statements
Excessive Public Count
Excessive Parameter List
Non Commenting Source Statements Method Count (NCSS Method Count)
Non Commenting Source Statements Type Count (NCSS Type Count)
Excessive Class Length
Too Many Fields

Performance

Avoid Dml Statements In Loops
Avoid Soql In Loops

Security

Apex Sharing Violations
Apex CRUD Violation
Apex Open Redirect
Apex XSS From URL Param
Apex SOQL Injection

Thanks for reading this post. Enjoy !!
Share on: