This article explains how to resolve a Salesforce error that blocks the uninstall of the Natterbox managed package because Natterbox Apex classes are locked by running or queued background jobs. It applies to Salesforce administrators uninstalling the Natterbox package. This is most commonly done in a sandbox, but Salesforce applies exactly the same locking rule in production orgs, so the same error and resolution apply there too.
Problem
When attempting to uninstall the Natterbox App package, the uninstall fails and Salesforce displays the following error:
The Apex class "TestUserTriggerHandler" is in use by queued or in progress Apex Batch Job(s) or Sharing Recalculation and cannot be deleted.
The same error may be shown for all of the Natterbox Apex classes.
Salesforce does not allow a managed package to be uninstalled while any Batch, Queueable, Future, or Scheduled job, or a Sharing Recalculation, is holding a lock on classes in the execution chain. This applies equally to sandbox and production orgs.
TestUserTriggerHandler is a User trigger handler. Any active batch or scheduled job that updates User records, including jobs from other (non-Natterbox) applications, causes Salesforce to lock TestUserTriggerHandler and the other Apex classes in the execution chain until the job finishes. This means the error can appear even when no Natterbox jobs are running.
Active Natterbox (nbavs) scheduled jobs also lock the Natterbox Apex classes until they are deleted. These are more common in production orgs, as scheduled jobs are often paused in a sandbox after a refresh.
If no jobs are running at the time of the uninstall, the error does not appear.
Resolution
⚠️
Warning: DO NOT abort any running batch job in a production org.
Aborting a job stops it before it completes. Always wait for running jobs to finish naturally, in both production and sandbox orgs. If you plan to uninstall from production, schedule a maintenance window and wait for any non-Natterbox batch jobs that update User records to finish.
Check For Running Apex Jobs
In the org you are uninstalling from, go to Setup, then use Quick Find to search for Apex Jobs.
Look for any jobs with a status of Holding, Queued, Preparing, or Processing. Check jobs that reference TestUserTriggerHandler or nbavs, and also any non-Natterbox batch job that is still processing, as it may be updating User records.
Wait for those jobs to finish. Do not abort them.
Go to Setup, then Apex Flex Queue, and check for any jobs in Holding status. Wait for these to clear before retrying the uninstall.
Check Scheduled Jobs
Even if no batch job is currently running, a scheduled job can keep a class locked or repeatedly re-queue a batch job.
Go to Setup, then use Quick Find to search for Scheduled Jobs.
Look for any Natterbox (nbavs) jobs, or any job linked to TestUserTriggerHandler.
Click Del to remove them.
Check For Sharing Recalculations
If Apex Jobs and Scheduled Jobs are completely clear and the error still appears:
Go to Setup, then Background Jobs (or Sharing Settings).
Check whether a Sharing Rule Recalculation or Group Membership recalculation is running.
If one is running, wait for it to finish before retrying the uninstall.
Retry The Uninstall
Once all queued and in-progress jobs have finished, and any Natterbox scheduled jobs have been deleted, go to Setup, then Installed Packages.
Click Uninstall next to the Natterbox (AVS) package.
FAQs
Why does this error appear when no Natterbox jobs are running?
TestUserTriggerHandler runs when User records are updated. If any batch or scheduled job is updating User records, including a job from another application, Salesforce locks TestUserTriggerHandler and the related Natterbox Apex classes until that job finishes.
Why is the error shown for every Natterbox Apex class?
Salesforce locks all Apex classes in the execution chain while the job is running, so the uninstall is blocked for each of the affected Natterbox classes, not only TestUserTriggerHandler.
Which jobs block the uninstall?
Any Batch, Queueable, Future, or Scheduled job, or a Sharing Recalculation, that holds a lock on classes in the execution chain. In Apex Jobs and the Apex Flex Queue, look for jobs with a status of Holding, Queued, Preparing, or Processing.
Can I abort the running job to speed up the uninstall?
No. Do not abort running batch jobs, and never abort them in a production org. Aborting stops the job before it completes. Wait for the job to finish naturally, then retry the uninstall from Installed Packages.
Can this happen when uninstalling from a production org?
Yes. Salesforce applies the same locking rule in production and sandbox orgs. Production orgs are also more likely to have active Natterbox scheduled jobs. Plan the uninstall for a maintenance window, let other applications' batch jobs finish, and delete any Natterbox scheduled jobs first.
Will the error appear if no jobs are running?
No. If the uninstall is run while no batch, scheduled, or sharing recalculation jobs are using the Natterbox Apex classes, the error does not appear.
What if Apex Jobs and Scheduled Jobs are clear but the error persists?
Check Background Jobs (or Sharing Settings) for a running Sharing Rule Recalculation or Group Membership recalculation, and wait for it to finish before retrying. If the error still appears, contact Natterbox Support.