# Configuration for Salesforce Metadata Rules

### Learning Objectives: <a href="#learning-objectives" id="learning-objectives"></a>

After reading this guide, you'll be able to:

* Create a custom Salesforce metadata Quality Profile
* Add Salesforce metadata types for a Salesforce Org analysis
* Add Salesforce metadata suffixes/extension for the analysis

### Create a Custom Salesforce Quality Profile <a href="#create-a-custom-salesforce-metadata-rule" id="create-a-custom-salesforce-metadata-rule"></a>

This article explains how to enable the Salesforce Metadata rules in the CodeScan Cloud environment.

1. Login to your **CodeScan** account.
2. Click on the **`Quality Profiles`** on your main organization page and then click on **`Create`** button.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FL4O6v91ncdvVxhKjQiqF%2Fimage.png?alt=media&#x26;token=18ece5f7-b2b7-44cb-9662-924699b5bdaf" alt=""><figcaption><p>Create Quality Profiles</p></figcaption></figure>
3. Create a new rule by selecting the language as **`Salesforce Metadata`** and name your new profile. You can choose the **`Parent rule`** as optional.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FcCtOpAi3Sr3S2kcqgCWz%2Fimage.png?alt=media&#x26;token=c0fd9ecd-f71e-4914-aea0-204bf9a5adb3" alt=""><figcaption><p>Create New Quality Profile</p></figcaption></figure>
4. Once you create the new quality profile, you will navigate to a new page where you need to click on the **`Activate More`** button on the left.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F6HP4N4JzgztpvMdIJlnr%2Fimage.png?alt=media&#x26;token=2b709b92-4b0b-45c1-8261-6e6e538f3c4b" alt=""><figcaption><p>Activate More</p></figcaption></figure>
5. Now, make sure on your left side of the page where you see the name of the rule you created, it is marked as **inactive**.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F7pG3Niv7yUe9hv5sykYx%2Fimage.png?alt=media&#x26;token=2336e3aa-dc00-46f2-9314-910b6e2041d1" alt=""><figcaption><p>Inactive</p></figcaption></figure>
6. Make sure that you activate the four rules referenced below by clicking on the **`Activate`** button beside the rule:
   * Record Type ID is Missing
   * Object Permissions should not be permissive
   * Enforce Org Security Settings
   * Custom fields must have a description field
7. Once activated, select the **`Active`** button under filters (beside the rule’s name).<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F5uRTgrKSgBi1JI8CFsfW%2Fimage.png?alt=media&#x26;token=f60bdab9-1813-4936-a8e5-2c78473b0138" alt=""><figcaption><p>Active Rule</p></figcaption></figure>

### Adding Salesforce metadata types for Salesforce Org analysis <a href="#adding-salesforce-metadata-types-for-the-analysis" id="adding-salesforce-metadata-types-for-the-analysis"></a>

To enable downloading metadata for your Salesforce project, you will need to change some project settings. Remember that the following will only work with code being pulled from Salesforce. &#x20;

If you are using a Git repository or any other method of scanning, please skip to the next step.

1. Once you are done with the activation of the custom rule, go to the project with the rules you wish to run the analysis and click on **`Project Settings > General settings`**.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F2GfNivrj9gATU1p8CvDs%2Fimage.png?alt=media&#x26;token=290b5d83-9ef2-4772-934e-35c8f7ad6406" alt=""><figcaption><p>General Settings</p></figcaption></figure>
2. Click the **`CodeScan`** tab on the left to open the [CodeScan](https://www.codescan.io/)-specific settings and access the **`CodeScan Cloud Download Types`**.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F7CXcSgOtx1Xgj0nAGBBE%2Fimage.png?alt=media&#x26;token=810ae55a-f269-47ae-bbb5-f6dfbf791376" alt=""><figcaption><p>Download Types</p></figcaption></figure>

3. The default values are *ApexClass, ApexComponent, ApexPage, ApexTrigger, AuraDefinitionBundle,* and *LightningComponentBundle*.
4. CodeScan is capable of analyzing all metadata types supported by Metadata API of Salesforce. Refer to the [Salesforce Developer API documentation](https://developer.salesforce.com/docs/metadata-coverage) to find the supported metadata types.
5. Under **`CodeScan Cloud Download Types`**, enter the Salesforce metadata types needed for the analysis, then select the **`Save`** button.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F8ngE0VgWlme0GPI4qqmG%2Fimage.png?alt=media&#x26;token=c0b215ec-039d-4a49-9e43-58b8b4a67efa" alt="" width="563"><figcaption><p>Save</p></figcaption></figure>

### Adding Salesforce metadata suffixes/extensions for the analysis <a href="#adding-salesforce-metadata-suffixesextensions-for-the-analysis" id="adding-salesforce-metadata-suffixesextensions-for-the-analysis"></a>

1. On the **`CodeScan`** section, scroll down to **`Scope`**, where you see **`Metadata File Suffixes`**.
2. Add the suffixes for the files to analyze.

{% hint style="info" %}
**Point to Note:**

Include your Salesforce metadata types for analysis under the **`Project Settings > General Settings > CodeScan > CodeScan Cloud Download Types`** section for your specific project. Later, add the relevant metadata types' suffixes/extension under the **`Metadata File Suffixes`** section.

Refer to the [**Salesforce Developer API**](https://developer.salesforce.com/docs/metadata-coverage) documentation to find the supported metadata types and their relevant suffixes/extension.
{% endhint %}

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FjVXohQ4pLW4mFeGESfF1%2Fimage.png?alt=media&#x26;token=840fc8b1-b94a-4b73-9ef0-1f06c122c9e9" alt=""><figcaption><p>Metadata File Suffixes</p></figcaption></figure>

3. Click **`Save`**.
4. Run the analysis again by navigating to the **`Project Settings > Project Analysis`** menu and selecting the **`Run Manual Analysis`** button. If your metadata files contain issues, you will see that reflected in the issues list.<br>

   <figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FEeG30o72PSQ5f41qAnAV%2Fimage.png?alt=media&#x26;token=ade9ad28-9bc4-499b-8ff7-83a6f95b91d3" alt=""><figcaption><p>Run Manual Analysis</p></figcaption></figure>

{% hint style="info" %}
**Note:** Make sure the line count will not show up on the line count breakdown as it is not a **language**. However, the issues will show up in the issues list as seen in the above figure.
{% endhint %}

### Additional Support <a href="#happy-to-help" id="happy-to-help"></a>

If you are still having trouble setting up metadata rules after reading the complete documentation, please contact the [support](https://support@codescan.io/) team, and we'll be happy to help.
