# Pipeline Operation: PMD Code Scan

The **Code Scan** operation analyzes your Salesforce metadata to identify code quality issues before deployment. It ensures that Apex classes, triggers, and components meet defined coding standards and thresholds.

This operation uses **Apex PMD** for static analysis and reports issues by severity (Blocker, Critical, Major, Minor, Info). The scan results are displayed in the pipeline job logs and can also be reviewed in detail through the **Code Scan Result** page.

#### Configuration Options <a href="#configuration-options" id="configuration-options"></a>

When creating or editing a pipeline step, configure the following:

* **Name**: Any descriptive label (e.g., *PMD CodeScan*).
* **Operation**: Code Scan.
* **Check type:** Apex PMD.
* **Description:** Short summary of what this scan performs (e.g., *Running CodeScan PMD*).
* **Severity threshold:** Defines the minimum severity level that will cause a failure (Blocker, Critical, Major, Minor, Info).
* **Next step (On pass / On fail):** Choose what the pipeline does next if the scan passes or fails.

#### Creating a Code Scan Step <a href="#creating-a-code-scan-step" id="creating-a-code-scan-step"></a>

1. Go to **Pipelines** → **Create** or **Edit** an existing pipeline.
2. Click the **+** icon between *Start* and *Stop.*
3. In the configuration panel, set the following fields:
   * **Name**: PMD CodeScan
   * **Operation**: Code Scan
   * **Check Type**: Apex PMD
   * **Description**: Running CodeScan PMD
   * **Severity Threshold:** Info
   * **Next Step:** On pass → Stop, On fail → Stop
4. Click Add to save the configuration.

Your pipeline now includes a Code Scan step, as shown below:

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252Flo6jcdgdIddCdQD4uHfX%252Fimage.png%3Falt%3Dmedia%26token%3De9bb8d8f-8262-420a-a0c8-6c52cde80374&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=af08f043&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FZ6zHpfgvleuNxoBI17Po%252Fimage.png%3Falt%3Dmedia%26token%3D0519db62-545b-4b2a-bea5-9e393e4a2bc2&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=320327b4&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FoH9SxueJVw7AerYiSIcT%252Fimage.png%3Falt%3Dmedia%26token%3Dbc77caf0-da06-4e10-8327-d62795a3196d&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=ebce1362&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

#### Running a Pipeline <a href="#running-a-pipeline" id="running-a-pipeline"></a>

1. Click Run Pipeline from the top-right corner.
2. The Code Scan operation executes automatically on all Apex classes and triggers in your connected branch.
3. A real-time banner appears showing the current status (*In Progress*, *Completed*, or *Exception*).
4. When finished, the job status appears as:
   * Completed: No violations found above the threshold.
   * Exception: Violations detected beyond the selected severity.

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FPE6a0JLtEMMI0vNo1Yhr%252Fimage.png%3Falt%3Dmedia%26token%3Dedbb5da8-186e-40b7-a233-1cf5d44688ac&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=e153dda6&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

#### Viewing Results <a href="#viewing-results" id="viewing-results"></a>

After execution, navigate to **Code → Branch → Activities → Pipelines.**

Each job shows key details such as:

* **Type**: Code Scan
* **Status**: Completed / Exception
* **Duration:** Total runtime
* **Created By**: User who initiated the scan

Click the job name to open detailed logs.

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FuQfrxz5f2kn5fFdezdmr%252Fimage.png%3Falt%3Dmedia%26token%3D8598e7b8-d5bf-41f0-b9a6-645d251ab5e7&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=8ac34e2f&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252Frdu5EYrwHOYfBfKzTBtx%252Fimage.png%3Falt%3Dmedia%26token%3D85b8d8a5-66e5-47f3-85cd-b8336202661e&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=ae6a3f50&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

#### Logs and Exceptions <a href="#logs-and-exceptions" id="logs-and-exceptions"></a>

When viewing a **failed or completed job**, select the PMD CodeScan step to review its output.

The log includes:

* **Code Analyzer started**
* **Salesforce project retrieved**
* **Analysis completed**
* **Result summary by severity**

**Example log output:**

Copy

```
[Info] Job started  
[Info] Retrieve Salesforce project started  
[Info] Retrieve Salesforce components completed  
[Info] Code analyzer started  
[Info] Code analyzer completed  
[Error] Job failed: Code scan exceeded allowed threshold
```

#### Code Scan Result Page <a href="#code-scan-result-page" id="code-scan-result-page"></a>

When you click **See** **result**, the system redirects to the **Code Scan Result page** showing a visual summary of issues grouped by severity:

* **Critical** – Must-fix issues that block deployment
* **High / Medium** – Warnings for potential problems
* **Low / Minor** – Informational or stylistic issues

Each file lists the number of issues and their categories (e.g., performance, security, maintainability).

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FJaB3JDuUgzzeINWKW8nc%252Fimage.png%3Falt%3Dmedia%26token%3Da027b7a1-7bff-41fd-aad9-8693626a4649&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=8b78492&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FZVmhtKTBNoxitCN1SHZ0%252Fimage.png%3Falt%3Dmedia%26token%3Db81a25e3-9251-4e18-a4d5-18a419e07122&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=ebd4e499&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

**Example:**

| Severity | Count |
| -------- | ----- |
| Critical | 0     |
| High     | 12    |
| Medium   | 10    |
| Low      | 0     |
| Minor    | 0     |

**Files scanned:**

* force-app/main/default/classes/RevvyDemo.cls – 9 issues
* force-app/main/default/classes/RevvyDemoTest.cls – 10 issues

#### File-Level Result View <a href="#file-level-result-view" id="file-level-result-view"></a>

Clicking a file name (e.g., RevvyDemo.cls) opens a **line-level detail view** showing every violation with rule, message, and location.

For each issue, the following information is displayed:

* **Rule**: The PMD rule violated (e.g., ApexDoc).
* **Message**: Description of the violation (e.g., *Missing ApexDoc @description*).
* **Line / Column:** Exact location of the issue in the source file.

| Rule    | Message                              | Line | Column |
| ------- | ------------------------------------ | ---- | ------ |
| ApexDoc | Missing ApexDoc Comment              | 1    | 21     |
| ApexDoc | Missing ApexDoc @description         | 5    | 19     |
| ApexDoc | Missing ApexDoc                      | 5    | 19     |
| ApexDoc | Missing or mismatched ApexDoc @param | 5    | 19     |
| ApexDoc | Missing ApexDoc @description         | 19   | 19     |

<div data-with-frame="true"><figure><img src="https://docs.revvy.io/~gitbook/image?url=https%3A%2F%2F599358484-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FlcWbuZareqS9jci4Vs22%252Fuploads%252FutkTUGkgrCqQgOeq0TUE%252Fimage.png%3Falt%3Dmedia%26token%3Dc219c827-973a-4961-8a7d-d634f578ffaa&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=7a94e8f6&#x26;sv=2" alt=""><figcaption></figcaption></figure></div>

#### Best Practices <a href="#best-practices" id="best-practices"></a>

* Run Code Scans automatically before every deployment.
* Set severity thresholds based on CI/CD rules (e.g., fail on *Critical*).
* Regularly review the **Code Scan Result** and fix recurring issues.
* Combine **Code Scan** with **Manual Step** for review and approval before production.
* Maintain consistent rule configurations across all environments.

[<br>](https://docs.revvy.io/devops-app/devops-app-devops.revvy.io/pipelines/configuring-pipeline-steps/pipeline-operation-manual-step)
