In this post, we will talk about the Salesforce code review checklist and how a customer, Project manager, administrator, and developer ensure that the code written for their uses follows Apex coding standards and avoids vulnerabilities and Security issues. Before discussing the Apex Best Practices Checklist, let’s see why we need code review.
What is Code Review in Salesforce?
Code review (sometimes called peer review) is a software quality assurance activity in which one or several people check a program mainly by viewing and reading parts of its source code. At least one of the persons must not be the code’s author. The persons performing the checking are called “reviewers.”
Why do we need Code Review?
Let us understand why we need standards and best practices for Code Review.
- Project Cost: 40%–80% of the lifetime cost of a piece of software goes to maintenance.
- Maintenance: Hardly any software is maintained for its whole life by the original author.
- Code readability: Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. Enhance code-readability to anybody wanting to do so in the future, reducing efforts for code maintenance. If you ship your source code as a product, you must ensure it is as well packaged and clean as any other product you create.
- Consistency: Introduce consistency to coding practices across the length and breadth of implementations.
- Code-reusability: Introduce code-reusability to repeatable processes and procedures.
- Significantly reduce development time and effort, improving productivity.
- Minimize POFs (point of failure) during implementations.
- Tech dept: It helps in tech debt prevention.
Basic Code Review
Let’s see what code reviewers view in code normally
- I can understand the code.
- Is the Class/Method is too big?
- DML/SOQL inside for loop
- Code coverage is 75+
- Code formatting & Naming Conventions
- Is code following standards/ Guidelines?
Expert Code Review
Let’s see what an expert code reviewer thinks about doing a code review. Here is the expert-level code review checklist.
Code review checklist
Here is the Salesforce code review checklist every project should have.
- Is code is following Standard Guidelines
- Naming convention in Salesforce
- Code Layouts and Formatting Salesforce.
- Keep your methods short
- Don’t repeat yourself
- Methods should do just one thing
- Is code following Defined Architecture?
- Order of Execution : Be aware of the order of executions.
- Exception Handling & Logging Framework: Look into the logging framework.
- Trigger Framework is appropriately implemented.
- Is the code meet the Non-Functional Requirement?
- Apex Best Practices: Prefer clicks over code wherever possible
- Avoid Hardcoding IDs
- Bulkify your Code
- No DML/SOQL inside for Loop
- Create one Trigger per object
- Apex Test class Best Practices
- Write meaningful tests with assertions.
- One assert per method.
- Follow Test Driven Development.
- Focus on 100% code coverage.
- Writing Test Methods to Verify Large Datasets
- Use TestDataFactory for data creation.
- Utilize Map for queries.
- Use of the Limits Apex Methods to Avoid Hitting Governor Limits
- OOAD ( Object Oriented Analysis & Design)
- Separation of Concerns
- DRY Principle
- SOLID Principle
- Single-responsibility principle: A piece of logic should only have a single responsibility….and the class, module, or function should entirely encapsulate responsibility.
- Open-closed principle: “Software entities … should be open for extension but closed for modification.”
- Dependency inversion principle: “Depend on abstractions and not concretions.”
- Dependency Injection
- Static Code Analysis : Use the tool to avoid spending too much time on code review, which the tool can do.
- Follow Integration Pattern & Best Practices
Code Review in Salesforce Video
Clean code should follow below best practices
- Easy to understand by other developers : readable by developers other than the one who developed it.
- Easy to maintain : lower chances of accidentally introducing bugs
- Modified without fear of breaking anything : Lot of developers take great pride in making the code compact – trying to do multiple things on one line – which might be impressive, but makes the code much harder to read and understand
Code Review Best Practices
Code review is one of the critical processes in any software development. It should be adequately documented so the team can follow code review best practices. Let’s see some of the code review best practices in Salesforce.
- Automate as much as possible using PMD or other tools
- Decide on code review goals
- Follow a standard checklist when submitting for review.
- During review
- Respond in a timely fashion
- Set clear expectations
- Aim to resolve the review quickly.
- Compile your review: Be respectful and frame feedback as request, not comments.
- Be open to follow-up
Further Learning
- Please check Clean Code in Salesforce recording.
Summary
If you like this post, please add a comment. I would like to have some more tips on this topic. Feel free to add some Tips and best practices in a comment. I will try to add to the post.
Please suggest a way on code review parameter basis on architecture diagram.
Related to Data preparation and 735% coverage check.
What if developer put summary method to cover up 75% guide line.
Awesome way to organize it!
Tkx for sharing such article.
Glad you like this code review checklist.
could not see reusability aspect.should add examples for each case.
This Salesforce code review checklist is a fantastic resource for ensuring high-quality Apex code! It emphasizes the importance of best practices, code readability, and maintainability, which are crucial for long-term project success. I especially appreciate the focus on automation and using tools like PMD. Great insights for developers!