When to enable test cleanup
Enabling test cleanup can be useful if:
Test records are taking up storage and impacting performance.
You want to create the same record each time and you have duplicate validation rules.
Enabling test cleanup
Turn on test cleanup in Test settings in the test builder side panel. On the next run, records the test creates are deleted, along with any records Salesforce deletes as a result, such as master-detail children removed by cascade delete. Cleanup doesn’t apply to runs from the test builder.
Note: Test data cleanup is disabled by default.
Viewing deleted records
You can see which records were deleted from the test run results page. The cleanup step is displayed at the end of the steps list. You’ll be able to see the object type and record ID for each deleted record.
Frequently asked questions
Does the cleanup still run if the test fails?
Yes, the cleanup will run at the end of the test whether the test passed or failed.
Will this delete or revert records edited in the test run?
No, we only delete records which have been created during the run directly.
Can I turn this on for some tests and have it off for others?
Yes, the setting is at the individual test level.
Does this delete records created in reusable tests?
Yes, if a record is created in a reusable test which is ran as a part of a test with cleanup enabled, it will also be cleaned up.



