Apex Deployment and Queueable Jobs: Can In-Flight Async Work Block or Fail a Production Deploy?
0 reputation · 14 Sept 2021, 11:37 UTC
0 reputation · 14 Sept 2021, 11:37 UTC
We deploy Apex changes to a production org (API v59.0 assumed) that runs Queueable and future jobs around the clock. The Deployment Status page separates Component Failures from Test Failures, but it is unclear how it reports interference from asynchronous jobs that are already queued or executing while the deployment's test run starts.
The documented behaviors we rely on are that production deployments enforce at least 75% org-wide Apex coverage via test execution, and that the Deployment Status log records the failing component or test class. What is not clear is the boundary between the deployment pipeline and the async job queue: whether a Queueable holding a lock on records touched by deployment tests can surface as a test failure indistinguishable from a genuine logic regression, and whether queued jobs are paused, allowed to complete, or left to collide with the validation window.
In a production org (API v59.0), Apex tests run in a dedicated, isolated test context during a deployment. That context does not pause or wait for existing asynchronous jobs. Queueable and future jobs that are already queued or executing can therefore run concurrently with the test run. If such a job holds a row‑level lock or updates the same records that a test method touches, the test will throw a System.DmlException: UNABLE_TO_LOCK_ROW (or a similar DML exception). The deployment process reports this as a test failure, indistinguishable from a logic regression unless the exception type is inspected.
SELECT FOR UPDATE) or perform DML on the same records a test modifies.UNABLE_TO_LOCK_ROW exception, which appears as a test failure in the Deployment Status log.System.DmlException: UNABLE_TO_LOCK_ROW or a similar DML exception.AssertException or other logic errors.AsyncApexJob for queued or processing jobs that might conflict with the deployment’s data changes:SELECT Id, JobType, Status, ApexClassId, ExtendedStatus
FROM AsyncApexJob
WHERE Status IN ('Queued','Processing','Holding')
AND JobType IN ('Queueable','Future');AsyncApexJob.cancelJob(jobId)) if you have the necessary Apex permissions.@IsTest(SeeAllData=false), avoid hard‑coded IDs, employ SELECT FOR UPDATE NOWAIT with retry logic, or use Platform Events to decouple work).UNABLE_TO_LOCK_ROW or a DML exception.To refine this recommendation, please provide the list of SObject types that your deployment modifies. Knowing the affected objects will help determine which pending async jobs are truly at risk of causing lock conflicts.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.