Code Quality

The open source PMD static code analyzer can identify over 40 different types of common programming flaws in Apex Code. The Metazoa Snapshot Org Management product has an Apex Code Quality Report that allows a Salesforce developer or administrator to run PMD on their Apex Classes and look for potential problems. The report can be shared with team members or archived for compliance documentation.

PMD Static Code Analysis
for Salesforce Developers

The open source PMD static code analyzer can identify over 40 different types of common programming flaws in Apex Code. PMD finds problems like unused variables, empty catch blocks, unnecessary object creation, and so forth. PMD has seven Rule Sets for Apex, including: Best Practices, Code Style, Design, Documentation, Error Prone, Performance, and Security. There are 46 individual Rules available that can identify common programming flaws in your Apex Classes. Strangely enough, nobody is quite sure what the acronym PMD stands for. This popular open source project has several unofficial names, the most appropriate is probably Programming Mistake Detector.

Our Metazoa Snapshot product has a report that analyzes code quality for selected Apex Tests in any Salesforce Org. The Snapshot Apex Code Quality report shows detailed information about each problem reported for the selected Apex Class. This report is used by Salesforce Administrators and Developers to find Apex Classes that have programming flaws. The priority level for individual rules can be edited by an administrator to customize the types of programming problems that are detected. The report can be shared with team members or archived for compliance documentation. You can also set up the report to monitor a Salesforce Org and send out an email or Chatter notification if Apex Code Quality falls below the desired level.

Snapshot can also analyze code quality before any Apex Class is deployed. Administrators can set up a code quality gateway which guarantees a certain level of Apex Code Quality for any Org. The short movie below shows how the Snapshot Apex Code Quality report works, and also shows the Code Quality options in the metadata deployment interface.

PMD Static Code Analysis with Snapshot

This document explains how to utilize PMD Static Code Analysis with Metazoa Snapshot for analyzing Apex code quality in Salesforce.

Introduction

Metazoa Snapshot is a tool for Salesforce org management and optimization. It integrates with PMD, an open-source static code analysis tool, to facilitate Apex code quality analysis within Salesforce organizations.

Setting up Code Quality Report

  1. Connect to Salesforce Orgs: Launch Snapshot Desktop and connect your Salesforce orgs.
  2. Access Apex Code Quality Report: Right-click on any connected org and select the Apex Code Quality Report option. This report provides an overview of Apex classes and test classes in the Salesforce organization.
  3. Analyze Apex Code: On the left-hand side of the Apex Code Quality Report, you will find a list of all Apex classes and tests. Click on any class or test to view the programming flaws in the selected Apex script in the middle section of the report. This section will highlight issues like security violations, where you may need to validate CRUD permissions before executing a SOQL operation.
  4. Select Classes and Tests for Report: You can select specific classes or tests to include in the report by checking the boxes next to them.
  5. Manage Report Quality Settings: Click the ‘Manage Quality’ button to control the definition of different problems. For example, you can set ‘Best Practices’ to be excluded from the report, while marking ‘Performance’ as highly recommended, and ‘Apex Documentation’ as optional. The report will be color-coded according to the preferences set.
  6. Scheduling Reports: The ‘Display Report’ tab enables you to schedule code quality reports for any Salesforce org. You can choose to send the report as a PDF, CSV, or HTML via email or Salesforce Chatter. The reports can be scheduled to send unconditionally or only when changes are required for the Salesforce org. This allows for monitoring and triggering alerts when issues arise.
  7. Code Quality in Deployment: The Code Quality Report can be utilized during the deployment process. In the main deployment tab, you can opt to test code quality as part of deployment. You can also set code quality gateways by selecting whether to halt deployment if a quality problem is reported and specifying the severity of the problem. This empowers administrators to enforce code quality standards for Salesforce orgs.

PMD Integration

Metazoa Snapshot integrates with PMD, an open-source static code analysis tool. PMD is well-regarded for its code quality analysis, particularly for Apex in Salesforce. It offers numerous rules for analyzing Apex code. PMD is compatible with Mac and Windows, and is easy to install on your local machine. By leveraging PMD within Snapshot, users can efficiently monitor their Salesforce organizations and establish code quality gateways to enforce coding standards.

Conclusion

Using PMD static code analysis with Metazoa Snapshot enhances the ability to monitor and maintain code quality within Salesforce organizations. Through scheduling, customizing reports, and integrating code quality checks into the deployment process, organizations can ensure that their Apex code adheres to the desired standards and best practices.

Learn More!

Snapshot provides powerful tools for Salesforce Administrators that help manage the change and release process, visualize org complexity, improve security and compliance, and lower the total cost of Org ownership. Visit the AppExchange to start a 14 day free trial or click the button below to schedule a demo.

🎉 Congratulations! 🎉

You’ve successfully completed the Metazoa Metadata Studio Certification Class. With the skills you’ve acquired, you’re now adept at harnessing the power of Metazoa’s Metadata Studio, seamlessly integrating artificial intelligence into Salesforce org management. You have earned you a certificate! Well done, and we wish you continued success in your future endeavors!