Delete Metadata Step and Test Level in deployments

When working with the destructive changes feature, you will notice that, apart from the Git Promotion step, a Delete Metadata step is created in the deployment record. 

User-added image

Git Promotion Step:

This is the step that will make the changes in Git and deploy components in the destination org. This step will not make any deletions in the destination org.
The Test Level on this step can be defined in the following ways:
  1. When creating the Deployment record from the Promotion record. The test level selected there will be applied to all the steps in the deployment record created.
  2. With the "Promotion Test Level" field on the user story if the checkbox "Promote & Deploy" is used.
  3. By changing the Test Level directly in the Git Promotion Step in the Deployment record.

If the Test Level on the Git Promotion step is set to RunSpecifiedTest, the test classes that will run when deploying will be those in the list of components in the deployment or those specified in the "Test Classes" attachment in the deployment record if the button Add Test Classes was used in the user stories.

Delete Metadata Step:

The only purpose of this step is to delete in the destination org the metadata components that were selected in the destructive changes commit.
The Test Level on this step can be defined in the following ways:
  1. When creating the Deployment record from the Promotion record. The test level selected there will be applied to all the steps in the deployment record created.
  2. With the promotion Test level field on the user story if the checkbox "Promote & Deploy" is used.
  3. By changing the Test Level directly in the Git Promotion Step in the Deployment record. This will required some manual steps since there is no field in the VF page that allows you to change the test level. 
    1. Copy the deployment record Id
    2. Go to the home tab.
    3. Remove home/home.jsp from the url.
    4. Paste DeploymentId?nooverride
    5. You are now in the standard layout for Deployment record, overriding the Visualforce page.
    6. In the Steps related list, click on the Delete Metadata step name.
    7. In this page you will see a text field called "dataJson". This field contains the test level for the Delete Metadata Step. The options are:
  • Blank value. No value on this field means Default test level selected by Salesforce automatically when deploying.
  • {"testLevel":"NoTestRun"}
  • {"testLevel":"RunSpecifiedTests"}
  • {"testLevel":"RunLocalTests"}
  • {"testLevel":"RunAllTestsInOrg"}
User-added image     User-added image

If you do not enter any value on the "dataJson" field, Salesforce will execute the Delete Metadata Step with the Default test level based on the components in the Delete Metadata Step and the type of environment you are deploying to.

What is the Default test level selected by Salesforce?

NoTestRun - This test level is the Default for development environments.
RunLocalTest - This test level is the Default for production environments that include Apex Classes or triggers.

Default Test Execution in Production:

When deploying to production, all tests, except those that originate from managed packages, are executed if your deployment package contains Apex classes or triggers. If your package doesn’t contain Apex components, no tests are run by default.

Please note that is not the same that Salesforce selects "No Test Run" as Default test level when no value is entered in the "dataJson" field that you select "No Test Run" as the test level for the Delete Metadata Step.

If you are trying to delete Classes or Triggers, the default value selected by Salesforce will be "RunLocalTest" if you leave the "dataJson" field blank. This will make all the local test classes to run. If you want to run only some specific test classes you will have to select "RunSpecifiedTests" as the test level.

If the Test Level on the Delete Metadata step is set to "RunSpecifiedTest", the test classes that will run when deploying will be those specified in the "Test Classes" attachment in the Delete Metadata step. This file must be created and attached manually in the Delete Metadata Step record. You can access this record following the steps mentioned above.

User-added image

Make sure the "Test Classes" file has no extension. If you see any extension in the file once attached, the file will not work.
If the option below is enable in your salesforce org, you will have to insert the attachment from the developer console, otherwise you will be adding a File and not an Attachment and the Default test level "RunLocalTest
" will be selected by Salesforce rather than 
"RunSpecifiedTests".

User-added image



This is an example of the content in the Test Classes attachment. 

[{"n":"CourseManagerTest"},{"n":"AppleWatchTest"}]

Considerations when working with Delete Metadata Steps.

1. If the test level selected is "Run Specified Test" but the "Test Classes" attachment doesn't exist in the Delete Metadata step or it's incorrect, Copado will applied the Default test level.
2. If the test level selected is "No Test Run" and you are deploying to Production, Copado will applied the Default test level.

In any of the 2 scenarios above, Salesforce will select the test level based on the components in the deployment and the environment you are deploying to as explained above.




 

How did we do?