Tests that are started from the Salesforce user interface (including the Developer Console) run in parallel. Parallel test execution can speed up test run time. Sometimes, parallel test execution results in data contention issues, and you can turn off parallel execution in those cases.
Required Editions
| Available in: Lightning Experience |
|
Available in: Enterprise, Performance, Unlimited, Developer, and Database.com Editions See Supported Editions for Flow Builder and Licenses for Integrated Features |
In particular, data contention issues and UNABLE_TO_LOCK_ROW errors can occur
in these cases.
- When tests update the same records at the same time—Updating the same records typically occurs when tests don’t create their own data and turn off data isolation to access the org’s data.
- When a deadlock occurs in tests that are running in parallel and that try to create records with duplicate index field values—Test data is rolled back when a test method finishes execution. A deadlock occurs when two running tests are waiting for each other to roll back data, which happens if two tests insert records with the same unique index field values in different orders.
You can prevent receiving those errors by turning off parallel test execution in the Salesforce user interface.
- From Setup, enter Application in the Quick Find box, select Application Test Execution, then click Options....
- In the Application Test Execution Options dialog, select Disable Parallel Apex Testing and then click OK.
For more information about test data, see Isolation of Test Data from Organization Data in Unit Tests in the Apex Code Developer Guide. This option doesn’t affect the execution order of tests, which continue to run asynchronously from the Application Test Execution page.