# Apex PMD

### What is PMD?  <a href="#what-is-pmd" id="what-is-pmd"></a>

PMD stands for Programming Mistake Detector. It is a source code analyzer that finds common mistakes in your code, like unused variables, if-else statements without braces, naming conventions of methods, SOQL in loops, and many more. It also includes CPD (for Copy/Paste Detector), which finds duplicate code in your files and makes you aware of improvements to make your code reusable.

Supported Version: ApexPMD upgraded to the latest 7.15.0 version.

### Setting up PMD in AutoRABIT <a href="#setting-up-pmd-in-autorabit" id="setting-up-pmd-in-autorabit"></a>

1. Log in to your AutoRABIT account.
2. From the AutoRABIT home page, hover your mouse over the **Admin** module and select the option: **My Account.**

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FUUNpRJTnrDJN5JCegNRs%2Fimage.png?alt=media&#x26;token=52a96fdd-5cf6-4e11-b905-774c64b0286e" alt="" width="306"><figcaption></figcaption></figure>

3. Go to the **Plugins** section.
4. Click on the **ApexPMD** checkbox under **Static Code Analysis**.
5. If you do have separate Apex PMD rules that you would like to carry out in AutoRABIT, you can upload the same. Click **Browse** to search for the file in your local machine. Usually, the file is in **XML** format. Once done, click **Upload**.
6. If the user has not uploaded any rules file, AutoRABIT will use the default Apex PMD rules file. However, you can update some of the fields in it.&#x20;
7. Download the default rule set in your local machine using the link as shown below.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FPAmUNQnJaAWq8qJ9oXv3%2Fimage.png?alt=media&#x26;token=79437edf-d0a8-46ff-a7e2-fff0b36232b1" alt=""><figcaption></figcaption></figure>

8. Edit the content and upload it once again.
9. Click **Save** and you are all set with ApexPMD Integration.

{% hint style="info" %}
**Point to Remember:** The current build of AutoRABIT supports Apex PMD with *Apex Classes, Apex Visualforce pages, and Triggers*.
{% endhint %}

### Running PMD during a CI Job <a href="#running-pmd-during-ci-job" id="running-pmd-during-ci-job"></a>

1. Go to the **New CI Job** screen.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FF9shPZWHVpnlqckfxwLK%2Fimage.png?alt=media&#x26;token=e6a57035-10c8-4ea3-8284-b4db069b419f" alt=""><figcaption></figcaption></figure>

2. Select any one of the criteria for your CI job. For example, **Deploy from Salesforce Org.**

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FrSH1dQETlX3DaRyXubNc%2Fimage.png?alt=media&#x26;token=9fa4df52-ad95-4f89-8b93-fe4dfeaf9cb9" alt=""><figcaption></figcaption></figure>

3. Enter a descriptive name in the **CI Job Name** field.
4. In the **Build** section, select your Salesforce Org or Version Control Repo/Branch.
5. Select the **Run Static Analysis Report** checkbox and choose **Apex PMD**.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2Fm5AoQkYP7Dk5m12s8zdH%2Fimage.png?alt=media&#x26;token=6ecb4728-eb81-44ce-b1ab-96c4c82297a9" alt=""><figcaption></figcaption></figure>

6. AutoRABIT allows you to set the criteria for running the ApexPMD SCA tool. This means running for all the apex classes or stating the period from when it will run. Also, you can set the priority, which means if the priority set is not achieved, the current build is unstable. This helps us in reporting the code quality of the developer team.
7. Fill in the remaining fields as per your requirements and click on **Save**.
8. Once the build is triggered for your CI Job, the SCA report can be found under the **Build Details** section on the **CI Job Result** page.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F5KUH5HNhB8GP5HGxRj2E%2Fimage.png?alt=media&#x26;token=874c8019-94c4-473a-9397-b74772494f89" alt=""><figcaption></figcaption></figure>

#### **PMD Report**

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FolPFphSHfYAp4Kls3qOU%2Fimage.png?alt=media&#x26;token=b1c7e622-e166-4f33-a06c-08f734aefc0e" alt=""><figcaption></figcaption></figure>

#### **PMD Report with Violations**

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FcAh2UYOJSrTXBLqt2kbN%2Fimage.png?alt=media&#x26;token=114cebd2-34eb-432f-8d50-2908e4ae152c" alt=""><figcaption></figcaption></figure>

### FAQs

#### I see some plugins require keys. Is this a license issue or can we get these keys and use the Static Code Analysis feature? <a href="#i-see-from-the-instructions-that-these-plugins-require-some-keys-is-it-a-license-issue-or-can-we-get" id="i-see-from-the-instructions-that-these-plugins-require-some-keys-is-it-a-license-issue-or-can-we-get"></a>

You can use Apex PMD and execute SCA without having to obtain a license for it. The other plugins are third-party tools and they require the license.

* [SCA for Checkmarx](https://knowledgebase.autorabit.com/product-guides/arm/integration-and-plugins/sca-for-checkmarx)
* [SCA for Apex PMD](https://knowledgebase.autorabit.com/product-guides/arm/integration-and-plugins/apex-pmd)
* [SCA for SonarQube](https://knowledgebase.autorabit.com/product-guides/arm/integration-and-plugins/sonarqube)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.autorabit.com/product-guides/arm/integration-and-plugins/apex-pmd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
