How to troubleshoot the 'Dependent class is invalid and needs > recompilation' exception?

908    Asked by ClareMatthews in Salesforce , Asked on May 4, 2023

I create a trigger on User that only inserts/updates another table when there are changes/insertions into the Department field that belong to User. It's working fine except sometimes I receive this exception in my email:


Apex script unhandled trigger exception by user/organisation: 0053000000xxx/00DQ0000003Lxxx Source organisation: 00D00000000hxxx (null) MyUpdateTrigger: execution of BeforeUpdate

caused by: line 55, column 24: Dependent class is invalid and needs recompilation: MyHelperClass: line 28, column 30: No such column 'Department' on entity 'User'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.


I check the line number: it points to an empty line.
The Department api name has no __c at the end.
I don't receive an email on this error when I do a manual test. I just received an email occasionally, meaning someone is firing the trigger.
Any ideas about the meaning of that error? How to troubleshoot this type of error?
Answered by Claudine Tippins

To diagnose the Error: Dependent class is in error and needs recompilation It is possible that if you get this error in the Force.com Eclipse IDE, there will be no further diagnostic information beyond the line number of the class being compiled that references some dependent class (which could be the dependent of a dependent ...). You're left puzzling over where the problem could be.

Tip

Copy-paste your code from Eclipse IDE into the Developer Console file for the same class and click Save. The Developer Console will report the full error message with a direct pointer to the underlying class that is in error
UPDATE for Eclipse: Turns out if you hover over the error line in Eclipse (tested in V38 Force.com IDE), the full detailed explanation as to which class is at issue will appear. You don't need to go to the Developer Console.
Here's an example:
From Eclipse IDE
Dependent class is in error and needs recompilation Line 14
From Developer Console
Dependent class is in error and needs recompilation Line 14, Class Foo line 56 method has incorrect signature (..)
where Foo is the dependent class in error and line 56 tells you why it is in error.

Your Answer

Answer (1)


The 'Dependent class is invalid and needs recompilation' exception is common in database systems like Oracle when a dependent object, such as a stored procedure or view, references another object that has changed. Here’s a detailed guide to troubleshoot and resolve this issue:

Steps to Troubleshoot and Resolve

Identify Invalid Objects:

Query the USER_OBJECTS or ALL_OBJECTS dictionary views to find invalid objects.

  SELECT object_name, object_typeFROM user_objectsWHERE status = 'INVALID';Check Dependencies:

Use the USER_DEPENDENCIES or ALL_DEPENDENCIES views to find the dependencies of the invalid objects.

  SELECT name, type, referenced_name, referenced_typeFROM user_dependenciesWHERE name IN (SELECT object_name FROM user_objects WHERE status = 'INVALID');Recompile Invalid Objects:

Recompile the invalid objects using the ALTER statement.

  -- For a specific procedureALTER PROCEDURE procedure_name COMPILE;-- For a specific packageALTER PACKAGE package_name COMPILE;-- For all invalid objects
  BEGIN    FOR rec IN (SELECT object_name, object_type FROM user_objects WHERE status = 'INVALID') LOOP        EXECUTE IMMEDIATE 'ALTER ' || rec.object_type || ' ' || rec.object_name || ' COMPILE';    END LOOP;END;

Check Compilation Errors:

If recompilation fails, check for compilation errors in the USER_ERRORS view.

  SELECT name, type, line, position, textFROM user_errorsWHERE name IN (SELECT object_name FROM user_objects WHERE status = 'INVALID');Resolve the Underlying Issues:

Address any issues identified from the compilation errors. This might involve correcting syntax errors, resolving missing references, or fixing logic errors in the dependent objects.

Recompile Again:

After resolving the errors, recompile the objects again.

Automate Recompilation (Optional):

If there are many invalid objects, you can use a script to recompile them automatically.

  BEGIN    FOR rec IN (SELECT object_name, object_type FROM user_objects WHERE status = 'INVALID') LOOP        EXECUTE IMMEDIATE 'ALTER ' || rec.object_type || ' ' || rec.object_name || ' COMPILE';    END LOOP;END;Example WorkflowIdentify Invalid Objects:
  SELECT object_name, object_typeFROM user_objectsWHERE status = 'INVALID';Output:
  markdownOBJECT_NAME     OBJECT_TYPE---------------------------MY_PROCEDURE    PROCEDUREMY_PACKAGE      PACKAGECheck Dependencies:
  SELECT name, type, referenced_name, referenced_typeFROM user_dependenciesWHERE name IN ('MY_PROCEDURE', 'MY_PACKAGE');

Output:

  NAME           TYPE       REFERENCED_NAME   REFERENCED_TYPE------------------------------------------------------------MY_PROCEDURE   PROCEDURE  MY_TABLE          TABLEMY_PACKAGE     PACKAGE    MY_VIEW           VIEW
5 Months

Interviews

Parent Categories