function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marc-André Bouchard 15Marc-André Bouchard 15 

Change Set: Dependent class is invalid and needs recompilation

The situation: I spun off a sandbox, and within that sandbox, I commented out large portions of code in order to disable a feature we're not going to use, and was linked to an installed package we wished to uninstall.  I ran the entire suit of Apex tests and everything passed with flying colors.

The problem: When I try to deploy the resulting change set into production, I get told "Dependent class is invalid and needs recompilation" for every single item of the change set.  It points to a method in one particular class as the source of the error - a method that I comment out, and I made sure every piece of code referring to that method was commented out too.

According to the help files, the solution was to recompile all Apex classes.  Very well.  Did this in Production, did this in Sandbox, started a new change set and deployment.  Still no dice, the error pops up again.  But I can't recompile any more than what I've already done, so what gives?

How am I supposed to get rid of this error and complete my deployment into production?
Best Answer chosen by Marc-André Bouchard 15
Andrew GAndrew G
I would try a simple change first.  
The error points to a method that you have removed - I assume it resides at a "deeper" level and is called by many other classes/methods.

Do the change where you comment out the call to the "uncompiled method" in one class/method only.  Adjust the Test class appropriately.   Then try and deploy just that class with it's test class.  Note that we are leaving the "uncompiled method" alone for the minute.  Just adjust the "higher" code so that it does not call the "uncompiled method" and update the relevant Test class so it doesn't test for any outcomes related to the "uncompiled method".

See how that goes first as a deployment.

If it's successful, do a change set for all the other higher classes with test classes, leaving the "uncompiled method" alone for the time being.  Once all dependencies are removed, comment out the "uncompiled method" and adjust any test class for that method and do a change set / deployment with that Apex code only.

Yes, i'm suggesting 3 x change sets to get rid of the old code, but if the first one does not resolve the issue, then no point trying the next 2.

HTH
Andrew

All Answers

AbhishekAbhishek (Salesforce Developers) 
Hi Marc,

Please follow all steps as mentioned in the below article,

https://help.salesforce.com/articleView?id=000340653&type=1&mode=1

Regards,
Salesforce support.
Marc-André Bouchard 15Marc-André Bouchard 15
I did what the help article says.  Unfortunately, the problem persists.
AbhishekAbhishek (Salesforce Developers) 
Marc,

If you have access to create a case with support? Please raise a case with CRM Support so that our team will assist you.
Andrew GAndrew G
I would try a simple change first.  
The error points to a method that you have removed - I assume it resides at a "deeper" level and is called by many other classes/methods.

Do the change where you comment out the call to the "uncompiled method" in one class/method only.  Adjust the Test class appropriately.   Then try and deploy just that class with it's test class.  Note that we are leaving the "uncompiled method" alone for the minute.  Just adjust the "higher" code so that it does not call the "uncompiled method" and update the relevant Test class so it doesn't test for any outcomes related to the "uncompiled method".

See how that goes first as a deployment.

If it's successful, do a change set for all the other higher classes with test classes, leaving the "uncompiled method" alone for the time being.  Once all dependencies are removed, comment out the "uncompiled method" and adjust any test class for that method and do a change set / deployment with that Apex code only.

Yes, i'm suggesting 3 x change sets to get rid of the old code, but if the first one does not resolve the issue, then no point trying the next 2.

HTH
Andrew
This was selected as the best answer
Marc-André Bouchard 15Marc-André Bouchard 15
Phew.  Code change complete, at last.  All in all, it took 6 deployments.

Stripping by layers proved to be the correct way to go about it.  Starting from the deployment of the full code, I cloned my deployment and removed components from it until all tests passed, then worked my way back down, until "that one class everybody calls" was finally commented out and deactivated.
Andrew GAndrew G
Glad you got it sorted.  Sometimes deployments are a pain.