Loading

Apex Invalid Type Compilation Error Referencing an Object

Udgivelsesdato: Aug 7, 2026
Beskrivelse
Issue
Apex code fails to compile and returns the error Invalid Type: {className}, where {className} is the object, class, or type the code references.
Symptoms
  • Saving or compiling an Apex class or trigger returns Invalid Type: {className}.
  • The referenced object, class, or type appears to exist in the org, yet the compiler reports it as invalid.
  • The same code may compile in one context (for example, the Developer Console) but fail in another, or vice versa.
Root Cause
Every Apex class and trigger is saved against a specific Salesforce API version, set through its Version Settings. The most common cause of Invalid Type: {className} is that the code references a component that is not exposed at the API version the class or trigger is saved with.
Most Apex language classes and methods are available to your code regardless of the API version the class is saved with. Some components, however, are version-specific, and referencing one of them from a class saved with an earlier API version can cause the compiler to not recognize the type and report Invalid Type:
  • Classes and methods in the ConnectAPI namespace are supported only in the API versions in which they were introduced; they are not available in earlier versions.
  • Standard objects and fields introduced in a later release are exposed only at that API version or later.
Raising the class or trigger's API version to one in which the referenced component is available resolves the mismatch.
Løsning

If you see Invalid Type: {className} during compilation, the referenced component most likely requires a higher API version than the one set on your Apex class or trigger. Resolve it as follows:

  1. Confirm the referenced object, class, or type name is spelled correctly and exists in the org, including any __c suffix or managed-package namespace.
  2. Identify the API version in which the referenced component became available.
  3. Update the Apex class or trigger to a compatible API version using one of the options below.
    • Option A — Developer Console: Open the class or trigger in the Developer Console and change its API version.
    • Option B — Setup: From Setup, enter Apex Classes (or Apex Triggers) in Quick Find and open the class or trigger. Click Edit, then Version Settings, and change the Version of the Salesforce API to a compatible version.
  4. Click Save.
  5. Verify: Recompile the code and confirm the Invalid Type: {className} error no longer appears. If the error persists, revisit step 1 to rule out a naming, __c suffix, or missing-namespace issue.
Vidensartikelnummer

000394713

 
Indlæser
Salesforce Help | Article